Cod sursa(job #340519)

Utilizator drag0s93Mandu Dragos drag0s93 Data 15 august 2009 10:39:27
Problema Lista lui Andrei Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.89 kb
#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;
}