Pagini recente » Cod sursa (job #2342542) | Cod sursa (job #780811) | Cod sursa (job #972156) | Cod sursa (job #1550308) | Cod sursa (job #1411126)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("nrcuv.in");
ofstream fout("nrcuv.out");
const int MAX_LETTERS = 32;
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][y] = true;
Restricted[y][x] = 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++)
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;
}