Pagini recente » Cod sursa (job #277987) | Cod sursa (job #2077405) | Cod sursa (job #1704664) | Cod sursa (job #1755210) | Cod sursa (job #1591214)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("nrcuv.in");
ofstream out("nrcuv.out");
const int dim = 26;
const int N_max = 1002;
const int mod = 104659;
bool A[dim + 1][dim + 1];
int nr[N_max][dim + 1]; // nr[i][j] == NR CUVINTELOR DE LUNGIME i CARE SE TERMINA CU LITERA j
int sol;
int N, M;
int main()
{
int i, j, k;
char x, y;
in >> N >> M;
for(i = 1; i <= M; i++)
{
in >> x >> y;
A[ (int)(x) - 97 + 1 ][ (int)(y) - 97 + 1 ] = true;
A[ (int)(y) - 97 + 1 ][ (int)(x) - 97 + 1 ] = true;
}
for(j = 1; j <= 26; j++) nr[1][j] = 1;
for(i = 2; i <= N; i++)
{
for(j = 1; j <= 26; j++)
for(k = 1; k <= 26; k++)
if(!A[k][j])
nr[i][j] += nr[i - 1][k]%mod;
}
for(i = 1; i <= 26; i++)
sol += nr[N][i]%mod;
out << sol;
return 0;
}