Pagini recente » Cod sursa (job #2800280) | Cod sursa (job #1863504) | Cod sursa (job #2396050)
#include <fstream>
using namespace std;
ifstream fin ("nrcuv.in");
ofstream fout ("nrcuv.out");
int n, m, ans, dp[1005][30];
char a, b;
bool pl[26][26];
int main() {
fin >> n >> m;
for (int i = 1; i <= m; ++i) {
fin >> a >> b;
pl[a - 'a'][b - 'a'] = true;
}
for (int c = 0; c < 26; ++c)
dp[1][c] = 1;
for (int poz = 2; poz <= n; ++poz) {
for (int c = 0; c < 26; ++c) {
for (int c2 = 0; c2 < 26; ++c2) {
if (!pl[c][c2] && !pl[c2][c]) {
dp[poz][c] += dp[poz - 1][c2];
dp[poz][c] %= 104659;
}
}
}
}
for (int c = 0; c < 26; ++c) {
ans += dp[n][c];
ans %= 104659;
}
fout << ans;
return 0;
}