Cod sursa(job #1779400)

Utilizator borcanirobertBorcani Robert borcanirobert Data 15 octombrie 2016 11:49:12
Problema Lista lui Andrei Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <fstream>
#include <cstring>
using namespace std;

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

const int MAXN = 1005;
const int NRLIT = 26;
const int MOD = 104659;
int N, M;
int D[MAXN][NRLIT];
bool ok[NRLIT][NRLIT];

void Read();
void Dinamica();
void Write();

int main()
{
    Read();
    Dinamica();
    Write();

    fin.close();
    fout.close();
    return 0;
}


void Read()
{
    char x, y;
    int i;
    memset(ok, true, sizeof(ok));

    fin >> N >> M;
    for ( i = 1; i <= M; i++ )
    {
        fin >> x >> y;
        ok[x - 'a'][y - 'a'] = ok[y - 'a'][x - 'a'] = false;
    }
}

void Dinamica()
{
    int i, j, k;

    for ( j = 0; j < NRLIT; j++ )
        D[1][j] = 1;

    for ( i = 2; i <= N; i++ )
        for ( j = 0; j < NRLIT; j++ )
            for ( k = 0; k < NRLIT; k++ )
                if ( ok[j][k] )
                    D[i][j] = ( D[i - 1][k] + D[i][j] ) % MOD;
}

void Write()
{
    int i;
    int rez = 0;

    for ( i = 0; i < NRLIT; i++ )
        rez = ( rez + D[N][i] ) % MOD;

    fout << rez << '\n';
}