Cod sursa(job #1591217)

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

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

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

bool A[dim][dim];

int nr[N_max][dim]; // 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][j]%mod + nr[i - 1][k]%mod )%mod;
    }

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

    out << sol%mod;

    return 0;
}