Cod sursa(job #2214821)

Utilizator mihai50000Mihai-Cristian Popescu mihai50000 Data 20 iunie 2018 10:57:13
Problema Lista lui Andrei Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <fstream>

using namespace std;

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

typedef long long ll;

const int MOD = 104659;

bool a[30][30];
int ans[1020][30];

ll s;

int main()
{
	int n, m;
	f >> n >> m;
	while(m--)
	{
		char x, y;
		f >> x >> y;
		x = x - 'a' + 1;
		y = y - 'a' + 1;
		a[x][y] = 1;
		a[y][x] = 1;
	}
	for(int i = 1; i <= 'z' - 'a' + 1; i++)
		ans[1][i] = 1;
	for(int i = 2; i <= n; i++)
		for(int j = 1; j <= 'z' - 'a' + 1; j++)
			for(int k = 1; k <= 'z' - 'a' + 1; k++)
				if(!a[j][k])
					ans[i][j] += ans[i - 1][k], ans[i][j] %= MOD;
	int sum = 0;
	for(int i = 1; i <= 'z' - 'a' + 1; i++)
		s += ans[n][i];
	s %= MOD;
	g << s;
}