Cod sursa(job #844388)

Utilizator antonioteoZait Teodor Antonio antonioteo Data 29 decembrie 2012 10:23:43
Problema Lista lui Andrei Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <fstream>
#include <bitset>
#define MOD 104659
using namespace std;
const char iname[] = "nrcuv.in";
const char oname[] = "nrcuv.out";
ifstream fin(iname);
ofstream fout(oname);
int N , M , i , sol;
char l1 , l2 , j , lc;
int DP[ 1004 ][ 164 ];
bitset < 164 > mark[ 164 ];
int main()
{
	fin >> N >> M;
	for (i = 1; i <= M; ++i)
	{
		fin >> l1 >> l2;
		mark[l1][l2] = 1;
		mark[l2][l1] = 1;
	}
	for (j = 'a'; j <= 'z'; ++j)
		DP[1][j] = 1;
	for (i = 1; i <= N; ++i)
	{
		for (j = 'a'; j <= 'z'; ++j)
		{
			for (lc = 'a'; lc <= 'z'; ++lc)
			{
				if (!mark[j][lc])
				{
					DP[i][j] = (DP[i - 1][lc] + DP[i][j]) % MOD;
				}
			}
		}
	}
	for (j = 'a'; j <= 'z'; ++j)
		sol = (sol + DP[N][j]) % MOD;
	fout << sol << '\n';
	return 0;
}