Cod sursa(job #2115933)

Utilizator lupulescu2001Lupulescu Vlad lupulescu2001 Data 27 ianuarie 2018 11:27:01
Problema Lista lui Andrei Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.85 kb
#include<fstream>

using namespace std;

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

int DP[2][27],N,M,A[27][27],Sol,MOD=104659;

int main()
{
    fin>>N>>M;
    for(int i=1; i<=M; i++)
    {
        char X,Y;
        fin>>X>>Y;
        A[X-'a'][Y-'a']=1;
        A[Y-'a'][X-'a']=1;
    }
    for(int i=0; i<26; i++)
        for(int j=0; j<26; j++)
            DP[0][i]=1;
    int Switch=1;
    for(int k=1; k<=N-1; k++)
    {
        for(int i=0; i<26; i++)
            DP[Switch][i]=0;
        for(int i=0; i<26; i++)
        {
            for(int j=0; j<26; j++)
            {
                if(A[i][j]==0)
                    DP[Switch][j]=(DP[Switch][j]+DP[1-Switch][i])%MOD;
            }
        }
        Switch=1-Switch;
    }
    for(int i=0; i<26; i++)
        Sol+=DP[1-Switch][i];
    fout<<Sol%MOD;

}