Cod sursa(job #2834362)

Utilizator amcbnCiobanu Andrei Mihai amcbn Data 16 ianuarie 2022 21:12:21
Problema Lista lui Andrei Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.98 kb
/* [A][M][C][B][N] / [K][R][I][P][6][8] */
// In the name of God
#include <bits/stdc++.h>
using namespace std;
const int mod = 104659, inf = 0x3f3f3f3f;
const char sp = ' ', nl = '\n';
ifstream fin("nrcuv.in");
ofstream fout("nrcuv.out");

int dp[1005][26];
bool can[26][26];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n, m;
    fin >> n >> m;
    for (int i = 0; i < m; ++i) {
        char a, b;
        fin >> a >> b;
        can[a - 'a'][b - 'a'] = can[b - 'a'][a - 'a'] = 1;
    }
    for (int i = 0; i < 26; ++i)
        dp[1][i] = 1;
    for (int i = 2; i <= n; ++i) {
        for (int j = 0; j < 26; ++j) {
            for (int k = 0; k < 26; ++k) {
                if (!can[j][k]) {
                    dp[i][j] += dp[i - 1][k];
                }
            }
            dp[i][j] %= mod;
        }
    }
    int ans = 0;
    for (int j = 0; j < 26; ++j) {
        ans = (ans + dp[n][j]) % mod;
    }
    fout << ans;
}