Cod sursa(job #3313724)

Utilizator Cristian_NegoitaCristian Negoita Cristian_Negoita Data 6 octombrie 2025 08:34:31
Problema Lista lui Andrei Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.93 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("nrcuv.in");
ofstream fout("nrcuv.out");
const int NMAX = 1001, SIGMA = 26, MOD = 104659;
int n, m, dp[NMAX][SIGMA];
bool check[SIGMA][SIGMA];

int main()
{
    fin >> n >> m;
    for(int i = 0; i < SIGMA; i++)
        for(int j = 0; j < SIGMA; j++)
            check[i][j] = true;
    while(m--)
    {
        char a, b;
        fin >> a >> b;
        check[a - 'a'][b - 'a'] = false;
        check[b - 'a'][a - 'a'] = false;
    }
    for(int i = 0; i < SIGMA; i++)
        dp[1][i] = 1;
    for(int i = 2; i <= n; i++)
        for(int j = 0; j < SIGMA; j++)
            for(int k = 0; k < SIGMA; k++)
                if(check[j][k])
                    dp[i][k] = (dp[i][k] + dp[i-1][j]) % MOD;
    int ans = 0;
    for(int i = 0; i < SIGMA; i++)
        ans = (ans + dp[n][i]) % MOD;
    fout << ans;

    fin.close();
    fout.close();
    return 0;
}