Cod sursa(job #2897358)

Utilizator matthriscuMatt . matthriscu Data 3 mai 2022 15:23:19
Problema Lista lui Andrei Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.68 kb
#include <bits/stdc++.h>
using namespace std;

#define NMAX 1005
#define MOD 104659

int main()
{
	freopen("nrcuv.in", "r", stdin);
	freopen("nrcuv.out", "w", stdout);

	int n, m;
	scanf("%d%d", &n, &m);

	bool pairs[26][26] {};

	char x, y;
	for (int i = 1; i <= m; ++i) {
		scanf(" %c %c", &x, &y);
		pairs[x - 'a'][y - 'a'] = pairs[y - 'a'][x - 'a'] = 1;
	}

	int dp[NMAX][26] {};

	for (int j = 0; j < 26; ++j)
		dp[1][j] = 1;

	for (int i = 2; i <= n; ++i)
		for (int j = 0; j < 26; ++j)
			for (int k = 0; k < 26; ++k)
				if (!pairs[j][k])
					dp[i][j] = (dp[i][j] + dp[i - 1][k]) % MOD;

	int ans = 0;
	for (int j = 0; j < 26; ++j)
		ans = (ans + dp[n][j]) % MOD;
	
	printf("%d\n", ans);
}