Cod sursa(job #758969)

Utilizator alexclpAlexandru Clapa alexclp Data 16 iunie 2012 14:54:02
Problema Lista lui Andrei Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 kb
#include<fstream>

using namespace std;

const int C = 104659;


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

bool comp[27][27];
int nr[1005][26];

void afisare(int n)
{
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=26;j++)
            out << nr[i][j] << " ";
        out << "\n";
    }
}

int main()
{

    int n, m;

    in >> n >> m >> ws;

    char x1, x2;

    for(int i=1;i<=m;i++)
    {
        in >> x1 >> ws >> x2 >> ws;
        comp[x1 - 'a' + 1][x2 - 'a' + 1] = comp[x2 - 'a' + 1][x1 - 'a' + 1] = true;
    }

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

    for(int i=2;i<=n;i++)
    {
        for(int j=1;j<=26;j++)
        {
            for(int k=1;k<=26;k++)
                if(!comp[j][k])
                    nr[i][j] = ( nr[i][j]  + nr[i-1][k] ) % C;
        }
    }

    int s = 0;

    for(int i=1;i<=26;i++)
        s = (s + nr[n][i]) % C;

    //afisare(n);

    out <<  s << "\n";

    return 0;
}