Pagini recente » Cod sursa (job #294801) | Cod sursa (job #949250) | Cod sursa (job #1260034) | Cod sursa (job #128594) | Cod sursa (job #340519)
Cod sursa(job #340519)
#include<cstdio>
using namespace std;
#define IN "nrcuv.in","r",stdin
#define OUT "nrcuv.out","w",stdout
int N , M ;
int hash[29][29];
int V[2020][29];
int main()
{
freopen(IN);
freopen(OUT);
scanf("%d%d\n",&N,&M);
char ch1 , ch2;
for(int i = 1 ; i <= M ; ++i)
{
scanf("%c %c\n",&ch1,&ch2);
hash[ch1 - 'a' + 1][ch2 - 'a' + 1] = 1;
hash[ch2 - 'a' + 1][ch1 - 'a' + 1] = 1;
}
/*
for(int i = 1 ; i <= 27 ; ++i)
{
printf("%d ",hash[i][0]);
for(int j = 1 ;j <= 27 ; ++j)
printf("%d ",hash[i][j]);
printf("\n");
}*/
for(int i = 1; i <= 26 ; ++i)
V[1][i] = 1;
for(int i = 2 ; i <= N ; ++i)
for(int j = 1 ; j <= 26 ; ++j){
for(int p = 1 ; p <= 26 ; ++p)
if(hash[j][p] == 0)
V[i][j] = (V[i][j] + V[i - 1][p]) % 104659;
}
int rez = 0;
for(int i = 1 ;i <= 26 ; ++i)
rez = (rez + V[N][i]) % 104659;
printf("%d\n",rez);
return 0;
}