Cod sursa(job #2674534)

Utilizator Elena05Dumitrache Marcela Elena05 Data 19 noiembrie 2020 16:37:34
Problema Lista lui Andrei Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <iostream>
#include <fstream>

using namespace std;

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

bool al[26][26];
int d[1000][26];

int main()
{
    int n, m;
    char x, y;
    fin >> n >> m;
    for(int i = 0; i < m; i++)
    {
        fin >> x;
        fin >> y;
        al[x - 'a'][y - 'a'] = true;
        al[y - 'a'][x - 'a'] = true;
    }
    for(int i = 0; i < 26; i++)
    {
        d[0][i] = 1;
    }
    for(int i = 1; i < n; i++)
    {
        for(int j = 0; j < 26; j++)
        {
            for(int k = 0; k < 26; k++)
            {
                if(al[j][k] == 0)
                {
                    d[i][j] += d[i-1][k];
                    d[i][j] %= 104659;
                }
            }
        }
    }
    int s = 0;
    for(int i = 0; i < 26; i++)
    {
        s += d[n-1][i];
        s %= 104659;
    }
    fout<<s;
    return 0;
}