Cod sursa(job #337207)

Utilizator drag0s93Mandu Dragos drag0s93 Data 2 august 2009 22:14:48
Problema Lista lui Andrei Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.31 kb
#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 - 53);
	return 0;
}