Cod sursa(job #1268269)

Utilizator alexandra_udristoiuUdristoiu Alexandra Maria alexandra_udristoiu Data 20 noiembrie 2014 19:35:40
Problema Lista lui Andrei Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include<fstream>
using namespace std;
int n, m, i, j, jj;
int a[26][1001], c[26][26];
char x, y;
ifstream fin("nrcuv.in");
ofstream fout("nrcuv.out");
int main(){
	fin>> n >> m;
	for(i = 1; i <= m; i++){
		fin>> x >> y;
		c[x-'a'][y-'a'] = 1;
		c[y-'a'][x-'a'] = 1;
	}
	for(i = 0; i < 26; i++){
		a[i][1] = 1;
	}
	for(i = 2; i <= n; i++){
		for(j = 0; j < 26; j++){
			for(jj = 0; jj < 26; jj++){
				if(c[j][jj] == 0){
					a[j][i] += a[jj][i-1] % 104659;
				}
			}
		}
	}
	int sum = 0;
	for(i = 0; i < 26; i++){
		sum+= a[i][n];
	}
	fout<< sum;
	return 0;
}