Cod sursa(job #2752588)

Utilizator andreiiorgulescuandrei iorgulescu andreiiorgulescu Data 18 mai 2021 17:48:13
Problema Lista lui Andrei Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <bits/stdc++.h>

using namespace std;

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

bool ok[30][30];
long long a[1005][30],n,m,i,j,q,modulo = 104659,s;
char c1,c2;

int main()
{
    in >> n >> m;
    for (i = 1; i <= m; i++)
    {
        in >> c1 >> c2;
        ok[c1 - 'a' + 1][c2 - 'a' + 1] = ok[c2 - 'a' + 1][c1 - 'a' + 1] = true;
    }
    for (i = 1; i <= 26; i++)
        a[1][i] = 1;
    for (i = 1; i < n; i++)
    {
        for (j = 1; j <= 26; j++)
        {
            for (q = 1; q <= 26; q++)
            {
                if (ok[j][q] == false)
                    a[i + 1][q] += a[i][j];
            }
            a[i + 1][j] %= modulo;
        }
    }
    for (i = 1; i <= 26; i++)
    {
        s += a[n][i];
        s %= modulo;
    }
    out << s;
    return 0;
}