Cod sursa(job #2350387)

Utilizator CyborgSquirrelJardan Andrei CyborgSquirrel Data 21 februarie 2019 12:00:38
Problema Lista lui Andrei Scor 35
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("nrcuv.in");
ofstream fout("nrcuv.out");

int beet(char c)
{
	return (c-'a');
}

bool nope[41][41];
int boop[2][41];
int main()
{
	int n, m;
	fin >> n >> m;
	for(int i = 0; i < m; i++){
		char a, b;
		int c, d;
		fin >> a >> b;
		c = beet(a); d = beet(b);
		nope[c][d] = nope[d][c] = true;
	}
	for(int i = 0; i < 26; i++){
		boop[0][i] = 1;
	}
	int curr = 1, prev = 0;
	for(int i = 1; i < n; i++){
		for(int j = 0; j < 26; j++){
			for(int k = 0; k < 26; k++){
				if(!nope[j][k]){
					boop[curr][k] += boop[prev][j];
				}
			}
			boop[prev][j] = 0;
		}
		swap(curr, prev);
	}
	int sum = 0;
	for(int i = 0; i < 26; i++){
		sum += boop[prev][i];
	}
	fout << sum;
}