Pagini recente » Cod sursa (job #341724) | Cod sursa (job #211097) | Cod sursa (job #2471192) | Cod sursa (job #1896476) | Cod sursa (job #2479938)
#include <bits/stdc++.h>
using namespace std;
ifstream fin ("nrcuv.in");
ofstream fout ("nrcuv.out");
const int N = 2005, mod = 104659, Z = 27;
int has[Z], d[N][Z];
bool f[Z][Z];
int main()
{
ios::sync_with_stdio(false);
fin.tie(0);
int n, m;
fin >> n >> m;
for(int i = 1; i <= m; ++i) {
char x, y;
fin >> x >> y;
if(x > y) swap(x, y);
if(f[x - 'a' + 1][y - 'a' + 1] == false) {
f[x - 'a' + 1][y - 'a' + 1] = true;
f[y - 'a' + 1][x - 'a' + 1] = true;
--has[x - 'a' + 1];
if(x != y) --has[y - 'a' + 1];
}
}
for(int i = 1; i <= 26; ++i) d[1][i] = 1;
for(int i = 1; i <= n; ++i) {
for(int ii = 1; ii <= 26; ++ii) {
for(int jj = 1; jj <= 26; ++jj) {
if(f[ii][jj] == false) d[i][jj] += d[i - 1][ii];
if(d[i][jj] >= mod) d[i][jj] %= mod;
}
}
}
int sum = 0;
for(int i = 1; i <= 26; ++i) sum += d[n][i];
sum %= mod;
fout << sum;
return 0;
}