Cod sursa(job #2668735)

Utilizator StfZZaharia Stefan StfZ Data 5 noiembrie 2020 11:43:49
Problema Lista lui Andrei Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.93 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'] = 1;
        al[y - 'a'][x - 'a'] = 1;
    }
    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;
    fin.close();
    fout.close();
    return 0;
}