Cod sursa(job #2193603)

Utilizator preda_dumitru75Preda Dumitru preda_dumitru75 Data 10 aprilie 2018 17:58:01
Problema Lista lui Andrei Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int const nmax = 1000;
int const modulo = 104659;
int cost[5 + nmax][5 + nmax];
int dp[5 + nmax][26];

int main()
{
  int n , m;
  in >> n >> m;
  for(int i = 0 ; i < 26 ;i++)
    for(int j = 0 ; j < 26 ;j++)
      cost[i][j] = 1;
  for(int i = 1 ; i <= m ;i++){
    char a , b;
    in >> a >> b;
    cost[a - 'a'][b - 'a'] = 0;
    cost[b - 'a'][a - 'a'] = 0;
  }
  for(int i = 1 ;i <= n ;i++){
    for(int h = 0 ; h < 26 ;h++)
      if(i == 1)
        dp[i][h] = 1;
      else
        for(int h2 = 0 ; h2 < 26 ;h2++)
          dp[i][h] = (dp[i][h] + dp[i - 1][h2] * cost[h2][h]) % modulo;
  }
  int sum = 0;
  for(int i = 0 ; i < 26 ;i++){
    sum += dp[n][i];
    sum %= modulo;
  }
  out << sum % modulo;
  return 0;
}