Pagini recente » Cod sursa (job #3269956) | Cod sursa (job #2951127) | Cod sursa (job #2526243) | wellcodesimulare4martie-special | Cod sursa (job #2115927)
#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;
}