Pagini recente » Cod sursa (job #1775530) | Cod sursa (job #1159362) | Cod sursa (job #2152751) | Cod sursa (job #1300935) | Cod sursa (job #2193603)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in ("nrcuv.in");
ofstream out ("nrcuv.out");
int const nmax = 1000;
int const modulo = 104659;
int cost[5 + nmax][5 + nmax];
int dp[5 + nmax][26];
int main()
{
int n , m;
in >> n >> m;
for(int i = 0 ; i < 26 ;i++)
for(int j = 0 ; j < 26 ;j++)
cost[i][j] = 1;
for(int i = 1 ; i <= m ;i++){
char a , b;
in >> a >> b;
cost[a - 'a'][b - 'a'] = 0;
cost[b - 'a'][a - 'a'] = 0;
}
for(int i = 1 ;i <= n ;i++){
for(int h = 0 ; h < 26 ;h++)
if(i == 1)
dp[i][h] = 1;
else
for(int h2 = 0 ; h2 < 26 ;h2++)
dp[i][h] = (dp[i][h] + dp[i - 1][h2] * cost[h2][h]) % modulo;
}
int sum = 0;
for(int i = 0 ; i < 26 ;i++){
sum += dp[n][i];
sum %= modulo;
}
out << sum % modulo;
return 0;
}