Cod sursa(job #1515394)

Utilizator DiClauDan Claudiu DiClau Data 1 noiembrie 2015 16:14:45
Problema Lista lui Andrei Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.11 kb
#include<stdio.h>
using namespace std;
const int lit = 27;
const int N = 1005, M = 2005;
int d[N][lit];
bool rel[lit][lit];
int main ()
{
    FILE *in, *out;
    in = fopen ("nrcuv.in", "r");
    out = fopen ("nrcuv.out", "w");
    int n, k, i;
    char a, b;
    fscanf (in, "%d%d", &n, &k);
    for (i = 1; i <= k; i++)
    {
        fscanf (in, "\n%c %c", &a, &b);
        rel[a - 'a' + 1][b - 'a' + 1] = true;
        rel[b - 'a' + 1][a - 'a' + 1] = true;
    }
    int j;
    for (i = 1; i < lit; i++)
        d[1][i] = 1;
    int s = 0, c;
    for (i = 2; i <= n; i++)
    {
        for (j = 1; j < lit; j++)
        {
            for (c = 1; c < lit; c++)
            {
                if (rel[j][c] == 0 && rel[c][j] == 0)
                {
                    s += d[i-1][c];
                    s %= 104659;
                }

            }
            d[i][j] += s;
            d[i][j] %= 104659;
            s = 0;
        }
    }
    s = 0;
    for (i = 1; i < lit; i++)
    {
        s += d[n][i];
        s %= 104659;
    }
    fprintf (out, "%d", s);
    return 0;
}