Cod sursa(job #679506)

Utilizator vitaminaXYZA.D.M. 2 vitaminaXYZ Data 13 februarie 2012 13:08:35
Problema Lista lui Andrei Scor 35
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include<fstream> 
#define MAX 1005
#define MOD 104659
using namespace std; 

ifstream in("nrcuv.in");
ofstream out("nrcuv.out");

bool A[30][30];
int Best[MAX][30], N, M, sol;

int main()
{
	char x, y;
	int i, j, k;
	
	in >> N >> M;
	for(i = 1; i <= M; i++)
	{
		in >> x >> y;
		A[x -'a' + 1][y - 'a' + 1] = A[y - 'a' + 1][x - 'a' + 1] = true;
	}
	for(i = 1; i <= 26; i++)
		Best[1][i] = 1;
	
	for(i = 2; i <= N; i++)
		for(j = 1; j <= 26; j++)
			for(k = 1; k <= 26; k++)
				if( A[j][k] == false )
					Best[i][j] = (Best[i][j] + Best[i-1][j])%MOD;
				
	for(i = 1; i <= 26; i++)
		sol = (sol + Best[N][i])%MOD;
	out << sol;
	
	return 0;
}