Pagini recente » Cod sursa (job #2039010) | Cod sursa (job #1723692) | Rating Ammie Westover (kroemera6011) | Cod sursa (job #2097293) | Cod sursa (job #1820539)
#include <iostream>
#include <fstream>
#define sigma 26
#define N 1000
#define MODULO 104659
using namespace std;
ifstream fin ("nrcuv.in");
ofstream fout ("nrcuv.out");
bool used[sigma][sigma];
int dynamic[N+1][sigma];
int totalLetters, totalExceptions;
inline void readVariables(){
fin >> totalLetters >> totalExceptions;
char x, y;
for ( ; totalExceptions; totalExceptions-- ){
fin >> x >> y;
used[x-'a'][y-'a'] = used[y-'a'][x-'a'] = true;
}
}
inline void solveProblem(){
for ( int index = 0; index < sigma; index++ ){
dynamic[1][index] = 1;
}
int solution = 0;
for ( int index = 2; index <= totalLetters; index++ ){
for ( int currentLetter = 0; currentLetter < sigma; currentLetter++ ){
for ( int previousLetter = 0; previousLetter < sigma; previousLetter++ ){
if ( !used[currentLetter][previousLetter] ){
dynamic[index][currentLetter] += dynamic[index-1][previousLetter] % MODULO;
}
}
}
}
for ( int index = 0; index < sigma; index++ ){
solution += dynamic[totalLetters][index] % MODULO;
}
fout << solution % MODULO << "\n" ;
}
int main(){
readVariables();
solveProblem();
return 0;
}