Cod sursa(job #2149547)

Utilizator Andrei17Andrei Pascu Andrei17 Data 2 martie 2018 18:42:02
Problema Lista lui Andrei Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <fstream>

using namespace std;

ifstream in("nrcuv.in");
ofstream out("nrcuv.out");

const int N = 1002, MOD = 104659;

int n, m, d[N][26];
bool c[26][26];

int main()
{
    int s = 0;
    char x, y;
    in >> n >> m;
    for (int i = 0; i < m; i++) {
        in >> x >> y;
        c[x - 'a'][y - 'a'] = true;
        c[y - 'a'][x - 'a'] = true;
    }
    in.close();

    fill(d[1], d[1] + 26, 1);
    for (int i = 2; i <= n; i++) {
        for (int j = 0; j < 26; j++) {
            for (int k = 0; k < 26; k++) {
                if (!c[j][k]) {
                    d[i][j] += d[i - 1][k];
                    d[i][j] %= MOD;
                }
            }
        }
    }

    for (int i = 0; i < 26; i++) {
        s += d[n][i];
        s %= MOD;
    }
    out << s;
    out.close();
}