Cod sursa(job #2396050)

Utilizator Iulia25Hosu Iulia Iulia25 Data 3 aprilie 2019 10:31:09
Problema Lista lui Andrei Scor 100
Compilator cpp-64 Status done
Runda simulare_03_04_2019 Marime 0.68 kb
#include <fstream>

using namespace std;

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

int n, m, ans, dp[1005][30];
char a, b;
bool pl[26][26];

int main()  {
  fin >> n >> m;
  for (int i = 1; i <= m; ++i)  {
    fin >> a >> b;
    pl[a - 'a'][b - 'a'] = true;
  }
  for (int c = 0; c < 26; ++c)
    dp[1][c] = 1;
  for (int poz = 2; poz <= n; ++poz)  {
    for (int c = 0; c < 26; ++c)  {
      for (int c2 = 0; c2 < 26; ++c2)  {
        if (!pl[c][c2] && !pl[c2][c])  {
          dp[poz][c] += dp[poz - 1][c2];
          dp[poz][c] %= 104659;
        }
      }
    }
  }
  for (int c = 0; c < 26; ++c)  {
    ans += dp[n][c];
    ans %= 104659;
  }
  fout << ans;
  return 0;
}