Cod sursa(job #2194195)

Utilizator stefan_creastaStefan Creasta stefan_creasta Data 12 aprilie 2018 16:10:38
Problema Lista lui Andrei Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <cstdio>
using namespace std;
const int NMAX = 2005;
const int CMAX = 30;
const int MOD = 104659;
bool vf[CMAX][CMAX];
int dp[NMAX][CMAX];

int main() {
  int n, m;
  freopen("nrcuv.in", "r", stdin);
  freopen("nrcuv.out", "w", stdout);
  scanf("%d%d\n", &n, &m);
  for(int i = 1; i <= m; ++i) {
    char a, b;
    scanf("%c %c\n", &a, &b);
    vf[a - 'a' + 1][b - 'a' + 1] = 1;
    vf[b - 'a' + 1][a - 'a' + 1] = 1;
  }
  for(int i = 1; i <= 'z' - 'a' + 1; ++i) {
    dp[1][i] = 1;
  }
  for(int k = 2; k <= n; ++k) {
    for(int j = 1; j <= 'z' - 'a' + 1; ++j) {
      for(int i = 1; i <= 'z' - 'a' + 1; ++i) {
        if(vf[i][j] == 0 && vf[j][i] == 0) {
          dp[k][i] = (dp[k][i] + dp[k - 1][j]) % MOD;
        }
      }
    }
  }
  int sol = 0;
  for(int i = 1; i <= 'z' - 'a' + 1; ++i) {
    sol = (sol + dp[n][i]) % MOD;
  }
  printf("%d\n", sol);
  return 0;
}