Cod sursa(job #1024175)

Utilizator teodor98Teodor Sz teodor98 Data 8 noiembrie 2013 12:38:15
Problema Lista lui Andrei Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
#define N 27
#define R 104659
using namespace std;
int a[1001][N],  c[N][N];
bool v[N][N];
char l1, l2;
ifstream in("nrcuv.in");
ofstream out("nrcuv.out");
int main()
{
    int n,m, s;
    in >> n >> m;
    for(int i=1;i<=m;i++)
    {

        in>>l1>>l2;
        v[l1 - 'a' +1][l2 - 'a' + 1] = a[l2 - 'a' +1][l2 - 'a'+1] = 1;
    }
    for(int i=1;i<=N;i++)
        a[1][i] = 1;
    for(int i=2;i<n;i++)
    {
        for(int k=1;k<N;k++)
        {
            for(int j=1;j<N;j++)
        {
            if(v[k][j] == 0)

            a[i][j] += v[i-1][j];

            a[i][j] %= R;
        }

        }

    }
    for(int i=1;i<N;i++)
    {
        s+= a[n][i];
    }
    out << s;
    return 0;
}