提交时间:2022-04-13 22:03:40
运行 ID: 48572
#include <bits/stdc++.h> using namespace std; #define mod(x, p) ((x) % (p) + (p)) % (p) // O(求x+求p) #define pyl 10005 int n, kkk, k1, k2; int ksm[105]; int f[55][2 * pyl + 5]; int main() { scanf("%d%d%d%d", &n, &kkk, &k1, &k2); ksm[0] = 1; for (int i = 1; i <= n + 1; i++) { ksm[i] = mod(ksm[i - 1] * k1, 11); } f[2][ksm[n] * k1 + ksm[n - 1] * k2 + pyl] = 1; for (int i = 3; i <= n + 1; i++) { for (int j = -pyl; j <= pyl; j++) { for (int k = -kkk; k <= kkk; k++) { if (-pyl <= j - k * ksm[n - i + 1] && j - k * ksm[n - i + 1] <= pyl) f[i][j + pyl] += f[i - 1][j - k * ksm[n - i + 1] + pyl], f[i][j + pyl] %= 998244353; } } } printf("%d\n", f[n + 1][k2 + pyl]); return 0; }