Pagini recente » Cod sursa (job #1600836) | Cod sursa (job #1621895) | Cod sursa (job #2376166) | Cod sursa (job #2745048) | Cod sursa (job #2674534)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("nrcuv.in");
ofstream fout("nrcuv.out");
bool al[26][26];
int d[1000][26];
int main()
{
int n, m;
char x, y;
fin >> n >> m;
for(int i = 0; i < m; i++)
{
fin >> x;
fin >> y;
al[x - 'a'][y - 'a'] = true;
al[y - 'a'][x - 'a'] = true;
}
for(int i = 0; i < 26; i++)
{
d[0][i] = 1;
}
for(int i = 1; i < n; i++)
{
for(int j = 0; j < 26; j++)
{
for(int k = 0; k < 26; k++)
{
if(al[j][k] == 0)
{
d[i][j] += d[i-1][k];
d[i][j] %= 104659;
}
}
}
}
int s = 0;
for(int i = 0; i < 26; i++)
{
s += d[n-1][i];
s %= 104659;
}
fout<<s;
return 0;
}