Pagini recente » preoji_6 | Cod sursa (job #2867616) | Cod sursa (job #608887) | Cod sursa (job #1691125) | Cod sursa (job #2551089)
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ifstream fin ("nrcuv.in");
ofstream fout ("nrcuv.out");
const int mod = 104659;
ll dp[1000][26];
bool mat[26][26];
int main()
{
int n, m; fin >> n >> m;
for(int i=1; i<=m; i++)
{
char a, b; fin >> a >> b; a -= 'a'; b -= 'a';
mat[a][b] = mat[b][a] = true;
}
for(int i=0; i<26; i++)
dp[0][i] = 1;
for(int j=1; j<n; j++)
for(int i=0; i<26; i++)
for(int k=0; k<26; k++)
if(!mat[i][k])
dp[j][i] = (dp[j][i] + dp[j-1][k]) % mod;
ll ans = 0;
for(int i=0; i<26; i++)
ans = (ans + dp[n-1][i]) % mod;
fout << ans;
return 0;
}