Cod sursa(job #424893)

Utilizator AndreiRSStatescu Andrei Rares AndreiRS Data 25 martie 2010 12:06:11
Problema Lista lui Andrei Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <stdio.h>
#include <string.h>
#define DIM 1001
#define MOD 104659

FILE *f1 = fopen("nrcuv.in","r");
FILE *f2 = fopen("nrcuv.out","w");

int a[26][DIM];
int p[26][26];

int n,m;
int i,j,k;
int x1,x2,s;

int main(){
	
	fscanf(f1,"%d %d\n",&n,&m);
	for(i=1; i<=m; i++){
		fscanf(f1,"%c %c\n",&x1,&x2);
		x1 -= 'a';
		x2 -= 'a';
		
		p[x1][x2] = 1;
		p[x2][x1] = 1;		
	}
	
	for(i=0; i<=25; i++)
		a[1][i] = 1;
	
	for(i=2; i<=n; i++){
		for(j=0; j<=25; j++){
			s = 0;
			
			for(k=0; k<=25; k++)
				if(p[j][k] == 0)
					s += a[1][n];
			
			a[2][j] = s % MOD;
		}
		
		for(j=0; j<=25; j++)
			a[1][j] = a[2][j];
		//memcpy(a[1],a[2]);
		
	}
	
	s = 0;
	for(i=0; i<=25; i++)
		s += a[1][i];	
	
	fprintf(f2,"%d",s % MOD);
	
	fclose(f1);
	fclose(f2);
	
	return 0;
}