Pagini recente » Cod sursa (job #917600) | Cod sursa (job #2806759) | Cod sursa (job #2528286) | Cod sursa (job #23537) | Cod sursa (job #2124091)
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("nrcuv.in");
ofstream out("nrcuv.out");
#define M 104659
long long dp[26][1001];
bool f[27][27];
int c[27];
int main(){
int n,m,i,j,k;
char x,y;
in>>n>>m;
if(n==1){
out<<26;
return 0;
}
for(i=1; i<=m; ++i){
in>>x>>y;
x-=96;
y-=96;
if(!f[x][y]){
++c[x];
if(x!=y) ++c[y];
f[x][y]=f[y][x]=1;
}
}
for(i=1; i<=26; ++i)
dp[i][1]=26-c[i];
for(i=2; i<n; ++i)
for(j=1; j<=26; ++j){
for(k=1; k<=26; ++k)
dp[j][i]+=dp[k][i-1]*(1-f[j][k]);
dp[j][i]%=M;
}
long long s=0;
for(i=1; i<=26; ++i)
s+=(dp[i][n-1]);
out<<s%M;
return 0;
}