Cod sursa(job #3220149)

Utilizator Ionut2212Nedelcu Alexandru Ionut Ionut2212 Data 2 aprilie 2024 16:55:37
Problema Lista lui Andrei Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <iostream>
#include <fstream>
#define mod 104659

using namespace std;
ifstream fin ("nrcuv.in");
ofstream fout ("nrcuv.out");
int f[28][28];
int dp[30][1001];
int main()
{
    int n, m;
    fin >> n >> m;
    for(int i = 1; i<=m; i++)
    {
        char x1, x2;
        fin >> x1 >> x2;
        f[x1 - 'a' + 1][x2 - 'a' + 1] = 1;
        f[x2 - 'a' + 1][x1 - 'a' + 1] = 1;
    }
    for(int j = 1; j <= 26; j++)
    {
        dp[j][1] = 1;
    }
    for(int i = 2; i<=n; i++)
    {
        for(int j = 1; j <= 26; j++)
        {
            for(int k = 1; k <= 26; k++)
            {
                if(f[j][k] == 0)
                dp[j][i] = (dp[j][i]+dp[k][i-1]) % mod;
            }
        }
    }
    int sum = 0;
    for(int i = 1; i <= 26; i++) sum = (sum+dp[i][n])%mod;
    fout << sum % mod;
    return 0;
}