Cod sursa(job #3141256)

Utilizator MAlex2019Melintioi George Alexandru MAlex2019 Data 13 iulie 2023 13:42:02
Problema Lista lui Andrei Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <iostream>
#include <fstream>
#include <set>

using namespace std;

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

const long long mod = 104659;
const int maxn = 1e3;
long long dp[maxn + 1];

int main() {
    int n, m;
    fin >> n >> m;
    set<pair<char, char>> rules;
    int cnt = 0;
    for (int i = 0; i < m; i++) {
        char x, y;
        fin >> x >> y;
        if (x == y) {
            cnt++;
            continue;
        }
        if (x > y)
            swap(x, y);
        rules.insert(make_pair(x, y));
    }
    cnt += rules.size()*2;

    dp[1] = 26;
    dp[2] = 676 - cnt;
    for (int i = 3; i <= n; i++)
        dp[i] = ((dp[i - 1]*26)%mod - (cnt*dp[i - 2])%mod)%mod;
    fout << dp[n] << '\n';

    return 0;
}