Pagini recente » Cod sursa (job #1276258) | Cod sursa (job #2771292) | Cod sursa (job #2051915) | Cod sursa (job #1261756) | Cod sursa (job #337206)
Cod sursa(job #337206)
#include<cstdio>
using namespace std;
#define NR 104659
#define IN "nrcuv.in","r",stdin
#define OUT "nrcuv.out","w",stdout
int hash[35][35];
int N , M;
long long V[1020][35];
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);
int ok = true;
for(int j = 1 ; j <= hash[ch1 - 'a' + 1][0] ; ++j)
if(hash[ch1 - 'a' + 1][j] == ch2 - 'a' + 1)
{
ok = false;
break;
}
if(ok == false) continue;
hash[ch1 - 'a' + 1][0]++;
hash[ch2 - 'a' + 1][0]++;
hash[ch1 - 'a' + 1][hash[ch1 - 'a' + 1][0]] = ch2 - 'a' + 1;
hash[ch2 - 'a' + 1][hash[ch2 - 'a' + 1][0]] = ch1 - 'a' + 1;
}/*
for(int i = 1 ; i <= 6 ; ++i)
{
printf("%d ",hash[i][0]);
for(int j = 1 ; j <= 6 ; ++j)
printf("%d ",hash[i][j]);
printf("\n");
}*/
int max = -200000;
for(int i = 1 ; i <= 27 ; ++i)
V[1][i] = 1;
for(int i = 2; i <= N ; ++i)
for(int j = 1 ; j <= 27 ; ++j)
{
for(int p = 1 ; p <= 27 ; ++p)
{
bool ok = true;
for(int t = 1 ; t <= hash[j][0] ; ++t )
if(hash[j][t] == p) {ok = false;break;}
if(ok == true) V[i][j] += V[i - 1][p];
}
}
int nr = 0;
for(int i = 1 ; i <= 27 ; ++i)
nr += V[N][i];
printf("%d\n",nr);
return 0;
}