Cod sursa(job #1591214)

Utilizator mihai.constantinConstantin Mihai mihai.constantin Data 5 februarie 2016 21:41:06
Problema Lista lui Andrei Scor 45
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.88 kb
#include <iostream>
#include <fstream>
using namespace std;

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

const int dim = 26;
const int N_max = 1002;
const int mod = 104659;

bool A[dim + 1][dim + 1];

int nr[N_max][dim + 1]; // nr[i][j] == NR CUVINTELOR DE LUNGIME i CARE SE TERMINA CU LITERA j

int sol;

int N, M;

int main()
{
    int i, j, k;
    char x, y;

    in >> N >> M;

    for(i = 1; i <= M; i++)
    {
        in >> x >> y;

        A[ (int)(x) - 97 + 1 ][ (int)(y) - 97 + 1 ] = true;
        A[ (int)(y) - 97 + 1 ][ (int)(x) - 97 + 1 ] = true;
    }

    for(j = 1; j <= 26; j++) nr[1][j] = 1;

    for(i = 2; i <= N; i++)
    {
        for(j = 1; j <= 26; j++)

            for(k = 1; k <= 26; k++)
                if(!A[k][j])
                    nr[i][j] += nr[i - 1][k]%mod;
    }

    for(i = 1; i <= 26; i++)
        sol += nr[N][i]%mod;

    out << sol;

    return 0;
}