Pagini recente » abx | Cod sursa (job #2957174)
#include <bits/stdc++.h>
using namespace std;
template <typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template <typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
using i64 = long long int;
const int INF = INT_MAX, MOD = 104659;
const long long LINF = LLONG_MAX;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {0, 0, 0, -1, 1, -1, 1, 1, -1};
const int dy[] = {0, -1, 1, 0, 0, -1, 1, -1, 1};
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
ifstream cin("nrcuv.in");
ofstream cout("nrcuv.out");
int N, M; cin >> N >> M;
vector<vector<bool>> pairs(26);
for (auto &row: pairs)
row.resize(26, false);
for (int i = 0; i < M; i++) {
char a, b;
cin >> a >> b;
pairs[a - 'a'][b - 'a'] = pairs[b - 'a'][a - 'a'] = true;
}
vector<vector<int>> dp(N + 1);
for (auto &row: dp)
row.resize(26,0 );
for (int i = 0; i < 26; i++)
dp[1][i] = 1;
for (int i = 2; i <= N; i++)
for (int j = 0; j < 26; j++)
for (int k = 0; k < 26; k++)
if (not pairs[j][k]) {
dp[i][k] += dp[i - 1][j];
dp[i][k] %= MOD;
}
int ans = 0;
for (int i = 0; i < 26; i++)
ans = (ans + dp[N][i]) % MOD;
cout << ans << "\n";
return 0;
}