Cod sursa(job #1090385)

Utilizator japjappedulapPotra Vlad japjappedulap Data 22 ianuarie 2014 17:39:16
Problema Lista lui Andrei Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <fstream>
using namespace std;

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

int n, m, sol;
bool B[30][30];
int DP[1005][30];
char x, y;

int main()
{
    is >> n >> m;
    for (int i = 1; i <= m; ++i)
        is >> x >> y, B[x-96][y-96] = B[y-96][x-96] = 1;
    for (int j = 1; j <= 26; ++j)
        DP[1][j] = 1;
    for (int i = 2; i <= n; ++i)
        for (int j = 1; j <= 26; ++j)
            for (int k = 1; k <= 26; ++k)
                if (B[k][j] == 0)
                {
                    DP[i][j] += DP[i-1][k];
                    DP[i][j] %= 104659;
                }

    for (int i = 2; i <= n; ++i)
        for (int j = 1; j <= 26; ++j)
        {
            sol += DP[i][j];
            sol %= 104659;
        }
    os << sol;
    is.close();
    os.close();
    return 0;
}