Cod sursa(job #1820538)

Utilizator AkrielAkriel Akriel Data 1 decembrie 2016 20:52:08
Problema Lista lui Andrei Scor 35
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.26 kb
#include <iostream>
#include <fstream>

#define sigma 26
#define N 1000

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];
                }
            }
        }
    }

    for ( int index = 0; index < sigma; index++ ){
        solution += dynamic[totalLetters][index];
    }
    fout << solution << "\n";
}

int main(){
    readVariables();
    solveProblem();
    return 0;
}