Pagini recente » Cod sursa (job #1589155) | Cod sursa (job #134252) | Cod sursa (job #2465455) | Cod sursa (job #36261) | Cod sursa (job #604785)
Cod sursa(job #604785)
#include<fstream>
#define modulo 104659
using namespace std;
bool ind[27][27];
int n,m,nr,a[1001][27];
char ch1,ch2;
int main(void){
ifstream fin("nrcuv.in");
ofstream fout("nrcuv.out");
fin>>n>>m;
for(int l=1;l<=m;++l){
fin>>ch1>>ch2;
ind[ch1-96][ch2-96]=true;
ind[ch2-96][ch1-96]=true;
}
fin.close();
for(int j=1;j<=26;++j) a[1][j]=1;
for(int i=2;i<=n;++i)
for(int j=1;j<=26;++j){
nr=0;
for(int k=1;k<=26;++k)
if(!ind[k][j])
nr=(nr+a[i-1][k])%modulo;
a[i][j]=nr;
}
nr=0;
for(int j=1;j<=26;++j) nr=(nr+a[n][j])%modulo;
fout<<nr%modulo;
fout.close();
return 0;
}