Cod sursa(job #2194076)

Utilizator MoodyFaresFares Mohamad MoodyFares Data 12 aprilie 2018 09:36:05
Problema Lista lui Andrei Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <cstdio>
#include <vector>

const int MAX_N = 1000;
const int SIGMA = 26;
const int MOD = 104659;

std::vector<int> g[SIGMA];
int d[1 + MAX_N][SIGMA];
bool ad[SIGMA][SIGMA];

int main() {
  freopen("nrcuv.in", "r", stdin);
  freopen("nrcuv.out", "w", stdout);
  
  int n, m;
  scanf("%d%d\n", &n, &m);
  for (int i = 1; i <= m; i++) {
    char ch1, ch2;
    scanf("%c %c\n", &ch1, &ch2);
    g[ch1 - 'a'].push_back(ch2 - 'a');
    g[ch2 - 'a'].push_back(ch1 - 'a');
    ad[ch1 - 'a'][ch2 - 'a'] = true;
    ad[ch2 - 'a'][ch1 - 'a'] = true;
  }
  for (int j = 0; j < SIGMA; j++)
    d[1][j] = 1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < SIGMA; j++) {
      for (int k = 0; k < SIGMA; k++) {
        if (ad[j][k] == 0) {
          d[i][j] = (d[i][j] + d[i - 1][k]) % MOD;
        }
      }
    }
  }
  int ans = 0;
  for (int j = 0; j < SIGMA; j++)
    ans = (ans + d[n][j]) % MOD;
  printf("%d\n", ans);
  return 0;
}