Cod sursa(job #2453902)

Utilizator bluestorm57Vasile T bluestorm57 Data 6 septembrie 2019 14:38:19
Problema Lista lui Andrei Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <bits/stdc++.h>

using namespace std;

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

const int mod = 104659;
const int NMAX = 1005;
const int ASMAX = 130;
int n,m,was[ASMAX],ans[ASMAX][NMAX],ANS;
bool Check[ASMAX][ASMAX];

int main(){
    int i,j,k;
    char x,y;
    f >> n >> m;
    for(i = 1 ; i <= m ; i++){
        f >> x >> y;
        if(Check[x][y] == 0){
            Check[x][y] = Check[y][x] = 1;
            was[x]--;
            was[y]--;
        }
    }

    for(i = 'a' ; i <= 'z' ; i++)
        ans[i][1] = 1;
    for(i = 2 ; i <= n ; i++)
        for(j = 'a' ; j <= 'z' ; j++)
            for(k = 'a' ; k <= 'z' ; k++)
                if(Check[j][k] == 0){
                    ans[j][i] += ans[k][i - 1];
                    ans[j][i] %= mod;
                }
    for(i = 'a' ; i <= 'z' ; i++)
        ANS = (ANS + ans[i][n]) % mod;

    g << ANS;
    return 0;
}