Cod sursa(job #2704054)

Utilizator bibiancapitu2004Pitu Bianca bibiancapitu2004 Data 9 februarie 2021 18:25:03
Problema Lista lui Andrei Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <fstream>
using namespace std;

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

int tab[30][30];
long long dp[1005][30] , s;

int main(){
    int n, p;

    in >> n >> p;

    for(int i = 0; i < p; i++)
    {
        char x, y;
        in >> x >> y;
        tab[x - 'a'][y - 'a'] = tab[y - 'a'][x - 'a'] = 1;
    }

    for(int j = 0; j < 26; j++)
    {
        dp[1][j] = 1;
    }

    for(int i = 2; i <= n; i++)
    {
        for(int j = 0; j < 26; j++)
        {
            for(int k = 0; k < 26; k++)
            {
                if( !tab[j][k] )
                {
                    dp[i][j] += dp[i - 1][k];
                    dp[i][j] %= 104659;
                }
            }
        }
    }

    for(int i = 0; i < 26; i++)
    {
        s += dp[n][i];
        s %= 104659;
    }

    out << s;
}