# Cod sursa(job #41549)

Utilizator Data 28 martie 2007 12:54:45 Lista lui Andrei 85 cpp done Arhiva de probleme 1.18 kb
``````#include <stdio.h>

short n, m, a[27][27];
long c[1001][26];
FILE *fout = fopen("nrcuv.out", "w");
void cit(){
short register i;
char x, y;
FILE *fin = fopen("nrcuv.in", "r");
fscanf(fin, "%hi %hi\n", &n, &m);
for(i=1; i<=m; i++){
fscanf(fin, "%c %c\n", &x, &y);
a[x-'a'+0][y-'a'+0] = a[y-'a'+0][x-'a'+0] = 1;
}
fclose(fin);
}
long sum(short x, char y){
short register i;
long suma = 0;
for(i=0; i<='z'-'a'; i++)
if(!a[i][y-'a'])
suma += (c[x][i]%104659);
return suma;
}
void solve(){
long suma = 0;
short register i, j;
for(i=0; i<='z'-'a'; i++)
c[1][i] = 1;
for(i=2; i<=n; i++){
for(j=0; j<='z'-'a'; j++)
c[i][j] = sum(i-1, (char)(j+'a'));
}
for(i=0; i<=26; i++){
suma += c[n][i];
suma %= 104659;
}
fprintf(fout, "%li", suma);
}
void tip(){
short register i, j;
for(i=1; i<=n; i++){
for(j=0; j<='z'-'a'; j++)
fprintf(fout, "%li ", c[i][j]);
fprintf(fout, "\n");
}
}
int main(){
cit();
/*    for(short register i=0; i<26; i++){
for(short register j=0; j<26; j++)
fprintf(fout, "%hi ", a[i][j]);
fprintf(fout, "\n");
}*/
solve();
//    tip();
fclose(fout);
return 0;
}

``````