Cod sursa(job #1108857)

Utilizator mlupseLupse-Turpan Mircea mlupse Data 16 februarie 2014 14:08:29
Problema Lista lui Andrei Scor 35
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <fstream>

using namespace std;
ifstream fin("nrcuv.in");
ofstream fout("nrcuv.out");
#define NMAX 1015
#define CH(s) (s - 'a')
#define MOD 104569

int N,M;
int Sol;

bool DieNachbarn[28][28];

int DP[NMAX][NMAX];

void Scannen()
{

    fin>>N>>M;
    char x,y;
    while(M--)
    {
        fin>>x>>y;
        DieNachbarn[CH(x)][CH(y)] = DieNachbarn[CH(y)][CH(x)] = true;
    }

}

void Losen()
{
    for(int j=0;j<26;j++)
        DP[1][j] = 1;

    for(int i=1;i<=N;i++)
        for(int j=0;j<26;j++)
            for(int k=0;k<26;k++)
                if(!DieNachbarn[k][j])
                    DP[i][j] = (DP[i][j] + DP[i-1][k]) % MOD;

    for(int j=0;j<26;j++)
        Sol = (Sol + DP[N][j]) % MOD;
}

void Drucken()
{
    fout<<Sol<<"\n";
}

int main()
{
    Scannen();
    Losen();
    Drucken();
    return 0;
}