Cod sursa(job #2115927)

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

using namespace std;

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

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

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[1-Switch][i];
            }
            DP[Switch][i]=DP[Switch][i]%104659;
        }
        Switch=1-Switch;
    }
    for(int i=0; i<26; i++)
        Sol+=DP[1-Switch][i];
    fout<<Sol;

}