Cod sursa(job #2707368)

Utilizator tomaionutIDorando tomaionut Data 16 februarie 2021 20:46:21
Problema Lista lui Andrei Scor 45
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <bits/stdc++.h>
using namespace std;

ifstream fin("nrcuv.in");
ofstream fout("nrcuv.out");
int n, m;
int a[1005][30],b[30][30];
long long sol;
int main()
{	
	int i, j,ind;
	char x, y;
	fin >> n >> m;
	for (i = 1; i <= m; i++)
	{
		fin >> x >> y;
		b[x - 'a'+1][y - 'a'+1] = 1;
		b[y - 'a'+1][x - 'a'+1] = 1;
	}
	for (i = 1; i <= 26; i++)
		a[1][i] = 1;
	for (i = 2; i <= n; i++)
	{	
		for (j = 1; j <= 26; j++)
			for (ind = 1; ind <= 26; ind++)
				if (b[j][ind] == 0 and b[ind][j] == 0)
					a[i][j] = (a[i][j] + a[i - 1][ind]) % 104659;
				
	}
	for (i = 1; i <= 26; i++)
		sol += a[n][i];
	fout << sol;




	return 0;
}