Pagini recente » Cod sursa (job #2860886) | Cod sursa (job #1728304) | Cod sursa (job #331093) | Cod sursa (job #2381234) | Cod sursa (job #2707368)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("nrcuv.in");
ofstream fout("nrcuv.out");
int n, m;
int a[1005][30],b[30][30];
long long sol;
int main()
{
int i, j,ind;
char x, y;
fin >> n >> m;
for (i = 1; i <= m; i++)
{
fin >> x >> y;
b[x - 'a'+1][y - 'a'+1] = 1;
b[y - 'a'+1][x - 'a'+1] = 1;
}
for (i = 1; i <= 26; i++)
a[1][i] = 1;
for (i = 2; i <= n; i++)
{
for (j = 1; j <= 26; j++)
for (ind = 1; ind <= 26; ind++)
if (b[j][ind] == 0 and b[ind][j] == 0)
a[i][j] = (a[i][j] + a[i - 1][ind]) % 104659;
}
for (i = 1; i <= 26; i++)
sol += a[n][i];
fout << sol;
return 0;
}