Pagini recente » Cod sursa (job #1467487) | Cod sursa (job #699549) | Cod sursa (job #1981282) | Cod sursa (job #948746) | Cod sursa (job #942779)
Cod sursa(job #942779)
#include<fstream>
using namespace std;
ifstream in("nrcuv.in");
ofstream out("nrcuv.out");
const int N = 1005;
int ad[30][30],d[30][N];
int n,m,sum;
char c1,c2;
void afisaread(){
int i,j;
for(i=1;i<=26;i++){
for(j=1;j<=26;j++) out<<ad[i][j]<<' ';
out<<'\n';
}
}
void afisared(){
int i,j;
for(i=1;i<=n;i++){
for(j=1;j<=26;j++) out<<d[i][j]<<' ';
out<<'\n';
}
}
int main(){
int i,j,k;
in>>n>>m;
for(i=1;i<=m;i++){
in>>c1>>c2;
ad[int(c1)-'a'+1][int(c2)-'a'+1]=1;
ad[int(c2)-'a'+1][int(c1)-'a'+1]=1;
}
//afisaread(); out<<'\n';
for(j=1;j<=26;j++) d[1][j]=1;
for(i=2;i<=n;i++)
for(j=1;j<=26;j++)
for(k=1;k<=26;k++) if(ad[k][j]==0) d[i][j]+=d[i-1][k];
//afisared(); out<<'\n';
for(j=1;j<=26;j++) sum+=d[n][j];
out<<sum;
return 0;
}