Pagini recente » Cod sursa (job #1585452) | Cod sursa (job #663482) | Cod sursa (job #2975033) | Cod sursa (job #727772) | Cod sursa (job #1411131)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("nrcuv.in");
ofstream fout("nrcuv.out");
const int MAX_LETTERS = 26;
const int LIM = 1005;
const int MOD = 104659;
bool Restricted[MAX_LETTERS][MAX_LETTERS];
int DP[LIM][MAX_LETTERS];
int N, R;
/*
DP[i][j] - cu semnificatia Nr. total de combinatii avand lungimea "i" incepand cu litera "j"
*/
void Read()
{
fin >> N >> R;
for(int i = 0; i < R; i++)
{
char x, y;
fin >> x >> y;
Restricted[x - 'a'][y - 'a'] = true;
Restricted[y - 'a'][x - 'a'] = true;
}
}
void Solve()
{
for(int i = 0; i < MAX_LETTERS; i++)
DP[1][i] = 1;
for(int i = 2; i <= N; i++)
for(int j = 0; j < MAX_LETTERS; j++)
for(int c = 0; c < MAX_LETTERS; c++)
if(!Restricted[j][c])
DP[i][j] = (DP[i][j] + DP[i-1][c]) % MOD;
int Result = 0;
for(int i = 0; i < MAX_LETTERS; i++)
Result = (Result + DP[N][i]) % MOD;
fout << Result << "\n";
}
int main()
{
Read();
Solve();
return 0;
}