Pagini recente » Cod sursa (job #526201) | Cod sursa (job #2778651) | Cod sursa (job #757222) | Cod sursa (job #2549206) | Cod sursa (job #2115933)
#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;
}