Cod sursa(job #2667080)

Utilizator daria_stoianStoian Daria Alexandra daria_stoian Data 2 noiembrie 2020 20:19:52
Problema Lista lui Andrei Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <fstream>
using namespace std;
const int N = 1001;
const int NL = 26;
const int M = 104659;
ifstream fin("nrcuv.in");
ofstream fout("nrcuv.out");
int dp[N][NL];
bool inco[NL][NL];
int main()	{
    int n, m, i, j, k;
    fin >> n >> m;
    for ( i = 0; i < m; i++){
        char c1, c2;
        fin >> c1 >> c2;
        inco[c1 - 'a'][c2 - 'a'] = inco[c2 - 'a'][c1 - 'a'] = true;
    }
    fin.close();
    for ( j = 0; j < NL; j++)	{
        dp[1][j] = 1;
    }
    for ( i = 2; i <= n; i++){
      for ( j = 0; j < NL; j++){
          for ( k = 0; k < NL; k++){
                if (!inco[j][k]){
                    dp[i][j] += dp[i - 1][k];
                    if (dp[i][j] >= M){
                        dp[i][j] -= M;
                    }
                }
            }
        }
    }
    int rez = 0;
    for ( j = 0; j < NL; j++)	{
        rez += dp[n][j];
        if (rez >= M){
            rez -= M;
        }
    }
    fout << rez;
    fout.close();
    return 0;
}