Pagini recente » Cod sursa (job #2904779) | Cod sursa (job #2713446) | Cod sursa (job #2269871) | Cod sursa (job #1742232) | Cod sursa (job #2271921)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("nrcuv.in");
ofstream fout("nrcuv.out");
const int NMAX = 26, MOD = 104659;
int DP[2][NMAX + 5], N, M, S, l = 1;
bool A[NMAX + 5][NMAX + 5];
int main()
{
char x, y;
fin >> N >> M;
while(M--) {
fin >> x >> y;
x -= 'a', y -= 'a';
A[x][y] = A[y][x] = true;
}
for(int i = 0; i <= NMAX; i++)
DP[0][i] = 1;
for(int ct = 2; ct <= N; ct++, l = 1 - l)
{
for(int i = 0; i < NMAX; i++) {
DP[l][i] = 0;
for(int j = 0; j < NMAX; j++)
if(!A[i][j])
DP[l][i] += DP[1 - l][j];
DP[l][i] %= MOD;
}
}
for(int i = 0; i < NMAX; i++)
S += DP[1 - l][i];
fout << S % MOD << '\n';
fin.close();
fout.close();
return 0;
}