Cod sursa(job #3283755)

Utilizator David2007David Preda David2007 Data 10 martie 2025 14:03:04
Problema Lista lui Andrei Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <bits/stdc++.h>

using namespace std;

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

const int mod=104659;

int v[3000][30],c[30][30];
int n,m,s;

int main()
{
    f>>n>>m;
    for(int i=1;i<=m;i++)
    {
        char a,b;
        f>>a>>b;
        c[a-'a'][b-'a']=1;
        c[b-'a'][a-'a']=1;
    }
    for(int i=0;i<26;i++)
        v[1][i]=1;
    for(int i=2;i<=n;i++)
        for(int j=0;j<26;j++)
            for(int l=0;l<26;l++)
                if(c[j][l]!=1 && c[l][j]!=1)
                    v[i][j]=(v[i][j]+v[i-1][l])%mod;
    for(int i=0;i<26;i++)
        s=(s+v[n][i])%mod;
    g<<s;
}