Pagini recente » Cod sursa (job #2933060) | Cod sursa (job #1436081) | Cod sursa (job #1827168) | Cod sursa (job #2170312) | Cod sursa (job #2707369)
#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%104659;
return 0;
}