Cod sursa(job #1411126)

Utilizator hopingsteamMatraguna Mihai-Alexandru hopingsteam Data 31 martie 2015 14:22:08
Problema Lista lui Andrei Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.05 kb
#include    <iostream>
#include    <fstream>

using namespace std;

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

const int MAX_LETTERS = 32;
const int LIM = 1005;
const int MOD = 104659;

bool Restricted[MAX_LETTERS][MAX_LETTERS];

int DP[LIM][MAX_LETTERS];
int N, R;

/*
 DP[i][j] - cu semnificatia Nr. total de combinatii avand lungimea "i" incepand cu litera "j"
*/

void Read()
{
    fin >> N >> R;
    for(int i = 0; i < R; i++)
    {
        char x, y;
        fin >> x >> y;
        Restricted[x][y] = true;
        Restricted[y][x] = true;
    }
}

void Solve()
{
    for(int i = 0; i < MAX_LETTERS; i++)
        DP[1][i] = 1;

    for(int i = 2; i <= N; i++)
        for(int j = 0; j < MAX_LETTERS; j++)
            for(int c = 0; c < MAX_LETTERS; c++)
                DP[i][j] = (DP[i][j] + DP[i-1][c]) % MOD;

    int Result = 0;
    for(int i = 0; i < MAX_LETTERS; i++)
        Result = (Result + DP[N][i]) % MOD;

    fout << Result << "\n";
}

int main()
{
    Read();
    Solve();
    return 0;
}