提交时间:2022-04-10 15:30:09
运行 ID: 48186
#include <bits/stdc++.h> using namespace std; #define int long long #define MOD 998244353 const int MXN = 100 + 5; int n, kk, k[MXN]; int ksm[MXN]; inline int dfs(int x, int nowz) { if (x >= n + 1) { if (abs(k[2] - nowz) <= kk) return 1; else return 0; } int ans = 0; for (int i = -kk; i <= kk; i++) { ans += dfs(x + 1, nowz + ksm[n - x + 1] * i); ans %= MOD; } return ans; } signed main() { //freopen("function.in", "r", stdin); //freopen("function.out", "w", stdout); cin >> n >> kk >> k[1] >> k[2]; if (kk == 0) { cout << 1 << endl; return 0; } if (k[1] == 0 && k[2] == 0) { int ans = 1; for (int i = 3; i <= n + 1; i++) { ans *= (2 * kk + 1); ans %= MOD; } cout << ans << endl; return 0; } ksm[1] = (k[1] + 110) % 11; for (int i = 2; i <= kk; i++) { ksm[i] = (ksm[i - 1] * k[1] + abs(k[1]) * 11) % 11; } cout << dfs(3, ksm[n] * k[1] + ksm[n - 1] * k[2]) << endl; return 0; }