Cod sursa(job #2667074)

Utilizator daria_stoianStoian Daria Alexandra daria_stoian Data 2 noiembrie 2020 20:14:52
Problema Lista lui Andrei Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <fstream>

using namespace std;

int mat[26][26], dp[1001][26];

int main(){
  ifstream fin ( "nrcuv.in" );
  ofstream fout ( "nrcuv.out" );
  int n, m, i, a, b;
  char x, y;
  fin >> n >> m;
  for ( i = 0; i < m; i ++ ){
    fin >> x >> y;
    mat[x][y] = mat[y][x] = 1;
  }
  for ( i = 'a'; i <= 'z'; i ++ ){
    dp[1][i] = 1;
  }
  b = 0;
  for ( i = 2; i <= n; i ++ ){
    for ( a = 'a'; a <= 'z'; a ++  ){
      for ( x = 'a'; x <= 'z'; x ++ ){
        if ( mat[x][a] == 0 ){
          dp[i][a] += dp[i - 1][x];
          dp[i][a] %= 104659;
        }
      }
    }
  }
  for ( i = 'a'; i <= 'z'; i ++ ){
    b += dp[n][i];
    b %= 104659;
  }
  fout << b;
  fin.close();
  fout.close();
  return 0;
}