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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| #include <bits/stdc++.h> using namespace std; const int N = 1e2 + 5,M = 1e4 + 5,P = 998244353; inline void Plus(int &x,const int &y) { x += y;if(x >= P) x -= P;} int n,m,V; int a[N]; int W; int dp[N][M];
inline void Addw(int x,int y) { for(int i = n;i >= x;i--) for(int j = W;j >= y;j--) Plus(dp[i][j],dp[i - x][j - y]); } inline void Delw(int x,int y) { for(int i = x;i <= n;i++) for(int j = y;j <= W;j++) Plus(dp[i][j],P - dp[i - x][j - y]); }
inline int Solve1() { for(int i = 0;i <= n;i++) for(int j = 0;j <= W;j++) dp[i][j] = 0; dp[0][0] = 1;int ans = 0; for(int r = 1,l = 1;r <= n;r++) { while(l <= r - 1 && a[r] - a[l] > m) Delw(1,a[l]),++l; for(int sz = max(0,V - (n - r));sz <= n;++sz) for(int i = max(0,sz * a[r] - V * m);i <= W;i++) Plus(ans,dp[sz][i]); Addw(1,a[r]); } return ans; } inline int Solve2() { for(int i = 0;i <= n;i++) for(int j = 0;j <= W;j++) dp[i][j] = 0; dp[0][0] = 1;int ans = 0; for(int l = n,r = n;l >= 1;l--) { while(r > l && a[r] - a[l] > m) Delw(1,a[r]),--r; for(int sz = max(0,n - V + 1 - (l - 1));sz <= n;++sz) for(int i = 0;i <= min(W,(n - V) * m + sz * a[l]);i++) Plus(ans,dp[sz][i]); Addw(1,a[l]); } return ans; }
inline void work() { cin >> n >> m >> V; W = 0; for(int i = 1;i <= n;i++) cin >> a[i],W += a[i]; sort(a + 1,a + n + 1); int ans = Solve1(); Plus(ans,Solve2()); cout << (ans + 1) % P << endl; } int main() { int T; cin >> T; while(T--) work(); return 0; }
|