Pagini recente » Cod sursa (job #1740644) | Cod sursa (job #2179090) | Cod sursa (job #2318765) | Cod sursa (job #286460) | Cod sursa (job #413082)
Cod sursa(job #413082)
#include<stdio.h>
const char in[]="nrcuv.in", out[]="nrcuv.out";
const int N=1005, mod=104659;
struct xy{
int x, y;}v[2005];
int a[N][28], n, m;
int main()
{char x, y;
freopen(in,"r",stdin);
freopen(out,"w",stdout);
scanf("%d%d\n", &n, &m);
for(int i = 1 ; i <= m; ++i)
{
scanf("%c %c\n",&x, &y);
v[i].x = x-'a' + 1;
v[i].y = y - 'a' + 1;
}
for(int j = 1; j <= 26; ++j)
a[1][j]=1;
for(int i = 2; i <= n; ++i)
for(int j = 1; j <= 26; ++j)
{
for(int k = 1; k <= 26; ++k)
{int ok=1;
for(int w=1; w <= m and ok; ++w )
if(v[w].x == j and v[w].y == k or v[w].x == k and v[w].y == j)ok=0;
if(ok)a[i][j] += a[i-1][k];a[i][j] %= mod;
}
}
int s=0;
for(int i = 1; i <= 26; ++i)
{s += a[n][i]; s %= mod;}
printf("%d\n", s);
return 0;
}