Pagini recente » Cod sursa (job #1565169) | Cod sursa (job #1524474) | Cod sursa (job #967739) | Cod sursa (job #664888) | Cod sursa (job #1525639)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("nrcuv.in");
ofstream out("nrcuv.out");
const int lit = 26;
const int N = 1001;
const int MOD = 104659;
int n, m;
bool posi[lit+1][lit+1];
int cuv[N][lit+1];
int main()
{
char x, y, c;
int i, j, k, s;
in >> n >> m;
for ( i = 1; i<= m; i++ )
{
in >> x >> y;
posi[x - 'a' + 1][y-'a' + 1] = true;
posi[ y - 'a' + 1][ x - 'a' + 1] = true;
}
for ( i = 1; i <= lit; i++ )
cuv[1][i] = 1;
for ( i = 2; i <= n; i++ )
for ( j = 1; j <= lit; j++ )
{
s = 0;
for ( k = 1; k <= lit; k++ )
{
if ( posi[j][k] == false )
{
s+=cuv[i-1][k];
s = s % MOD;
}
}
cuv[i][j] = s;
}
s = 0;
for ( i = 1; i<= lit; i++ )
{
s+= cuv[n][i];
s = s % MOD;
}
out << s;
return 0;
}