Pagini recente » Cod sursa (job #221888) | Cod sursa (job #3316547) | Cod sursa (job #274554) | Cod sursa (job #1325262) | Cod sursa (job #3313724)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("nrcuv.in");
ofstream fout("nrcuv.out");
const int NMAX = 1001, SIGMA = 26, MOD = 104659;
int n, m, dp[NMAX][SIGMA];
bool check[SIGMA][SIGMA];
int main()
{
fin >> n >> m;
for(int i = 0; i < SIGMA; i++)
for(int j = 0; j < SIGMA; j++)
check[i][j] = true;
while(m--)
{
char a, b;
fin >> a >> b;
check[a - 'a'][b - 'a'] = false;
check[b - 'a'][a - 'a'] = false;
}
for(int i = 0; i < SIGMA; i++)
dp[1][i] = 1;
for(int i = 2; i <= n; i++)
for(int j = 0; j < SIGMA; j++)
for(int k = 0; k < SIGMA; k++)
if(check[j][k])
dp[i][k] = (dp[i][k] + dp[i-1][j]) % MOD;
int ans = 0;
for(int i = 0; i < SIGMA; i++)
ans = (ans + dp[n][i]) % MOD;
fout << ans;
fin.close();
fout.close();
return 0;
}