Cod sursa(job #757153)

Utilizator DumitracheIulianDumitrache Iulian DumitracheIulian Data 11 iunie 2012 11:45:32
Problema Lista lui Andrei Scor 35
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream in ("nrcuv.in");
ofstream out("nrcuv.out");
int const N=1001;
int const M=2001;
int n,m,mat[N][28];
bool p[28][28];

void init ()
{
    for(int i=0;i<26;i++)
        for(int j=0;j<26;j++)
            p[i][j]=true;
}
void citire()
{
    in>>n>>m>>ws;
    for(int i=1;i<=m;i++)
    {
        char a,b;
        in>>a>>ws>>b>>ws;
        p[a-'a'][b-'a']=false;
        p[b-'a'][a-'a']=false;
    }
}
void complet()
{
    for(int i=0;i<26;i++)
        mat[1][i]=1;
    for(int i=2;i<=n;i++)
        for(int j=0;j<26;j++)
            for(int k=0;k<26;k++)
                if(p[j][k])
                    mat[i][k]+=mat[i-1][j];
}
void rez()
{
    int r=0;
    for(int i=0;i<26;i++)
        r+=mat[n][i];
    out<<r%104659<<"\n";
}
/*void afis ()
{
    out<<"----------\n";
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<26;j++)
            out<<mat[i][j]<<"\t";
        out<<"\n";
    }
}*/
int main()
{
    init();
    citire();
    complet();
    rez();
    //afis();
    return 0;
}