1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| #include <iostream> #define maxn 1010 #define maxm 10010 #define maxk 11 using namespace std;
const int p = 998244353; inline int add(int x, int y) { return (x += y) >= p ? x - p : x; } inline int mul(int x, int y) { return 1ll * x * y % p; } inline int add(initializer_list<int> lst) { int s = 0; for (auto t : lst) s = add(s, t); return s; } inline int mul(initializer_list<int> lst) { int s = 1; for (auto t : lst) s = mul(s, t); return s; } int pow_mod(int x, int n) { int s = 1; for (; n; n >>= 1, x = mul(x, x)) if (n & 1) s = mul(s, x); return s; }
int n, m, k, a[maxn];
int f[2][maxm][maxk];
int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
cin >> n >> k >> m; k = n - k + 1; for (int i = 1; i <= n; ++i) cin >> a[i]; f[1][a[1]][1] = 1; for (int i = 1, s = 1, t = 0; i < n; ++i, swap(s, t)) { fill(f[t][0], f[t][0] + maxm * maxk, 0); f[t][a[i + 1]][1] = 1; for (int j = 0; j <= m; ++j) for (int k = 1; k <= ::k; ++k) { if (!f[s][j][k]) continue; f[t][j][k] = add(f[t][j][k], f[s][j][k]); f[t][j + a[i + 1]][k] = add(f[t][j + a[i + 1]][k], p - f[s][j][k]); if (k < ::k) f[t][j + a[i + 1]][k + 1] = add(f[t][j + a[i + 1]][k + 1], f[s][j][k]); } } int ans = 0; for (int i = 0; i <= m; ++i) ans = add(ans, mul({ f[n & 1][i][k], pow_mod(i, p - 2), m })); cout << ans << "\n"; return 0; }
|