Cod sursa(job #955187)

Utilizator mihai0110Bivol Mihai mihai0110 Data 31 mai 2013 01:58:57
Problema Lista lui Andrei Scor 35
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <fstream>
#include <string>

#define MAXN 1002

using namespace std;


bool graph[30][30];
int sol[30][MAXN];

int main(void)
{
	int n, m;

	ifstream f("nrcuv.in");
	ofstream g("nrcuv.out");

	f >> n >> m;

	for (int i = 'a'; i <= 'z'; i++)
		for (int j = 'a'; j <= 'z'; j++)
			graph[i - 'a'][j - 'a'] = true;

	while (m--) {
		string s1, s2;
		f >> s1 >> s2;
		graph[s1[0] - 'a'][s2[0] - 'a'] = false;
		graph[s2[0] - 'a'][s1[0] - 'a'] = false;
	}

	for (int i = 'a'; i <= 'z'; i++) {
		sol[i - 'a'][1] = 1;
	}

	for (int i = 2; i <= n; i++) {
		for (int c1 = 'a'; c1 <= 'z'; c1++)
			for (int c2 = 'a'; c2 <= 'z'; c2++)
				sol[c2 - 'a'][i] += graph[c1 - 'a'][c2 - 'a'] ? sol[c1 - 'a'][i - 1] : 0;
	}

	int res = 0;
	for (int i = 'a'; i <= 'z'; i++)
		res += sol[i - 'a'][n];

	g << res << "\n";

	f.close();
	g.close();
	return 0;
}