Cod sursa(job #1844525)

Utilizator Nevermore10Macovei Cosmin Nevermore10 Data 10 ianuarie 2017 01:25:45
Problema Lista lui Andrei Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("nrcuv.in");
ofstream g("nrcuv.out");
int n,m,pereche[27][27],dp[1002][26];

int main() {
    f >> n >> m;
    for(int i = 0; i < m; i++) {
        char a,b;
        f >> a >> b;
        pereche[a - 'a'][b - 'a'] = true;
        pereche[b - 'a'][a - 'a'] = true;
    }
    
    for(int i = 0; i < 26; i++)
        dp[1][i] = 1;
    for(int i = 2; i <= n; i++) {
        for(int j = 0; j < 26; j++) {
            for(int k = 0; k < 26; k++) {
                if(!pereche[j][k]) {
                    dp[i][j] = (dp[i][j] + dp[i-1][k]) % 104659;
                }
            }
        }
    }
    int x = 0;
    for(int i = 0; i < 26; i++) {
        x = (x + dp[n][i]) % 104659;
    }

    g << x;

    return 0;
}