Pagini recente » Cod sursa (job #1245718) | Cod sursa (job #144531) | Cod sursa (job #3130481) | Cod sursa (job #750797) | Cod sursa (job #338980)
Cod sursa(job #338980)
#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];
bool cautare(int ch,int cautat)
{
for(int i = 1 ; i <= hash[ch][0] ; ++i)
if(hash[ch][i] == cautat)
return false;
return true;
}
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);
bool ok = true;
for(int p = 1 ; p <= hash[ch1 - 'a' + 1][0]; ++p)
if(hash[ch1 - 'a' + 1][p] == ch2 - 'a' + 1){
ok = false;
break;
}
hash[ch1 - 'a' + 1][0]++;
if(ok == false)
continue;
if(ch1 != ch2){
hash[ch2 - 'a' + 1][0]++;
hash[ch2 - 'a' + 1][hash[ch2 - 'a' + 1][0]] = ch1 - 'a' + 1;
}
hash[ch1 - 'a' + 1][hash[ch1 - 'a' + 1][0]] = ch2 - 'a' + 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(cautare(p,j) == true)
V[i][j] += V[i - 1][p];
}
long long rez = 0;
for(int i = 1 ;i <= 26 ; ++i)
rez += V[N][i];
printf("%lld\n",rez % 104659);
return 0;
}