P14360
一种比较傻的思路,至少相对于其他题解来说是这样的。
对于
此时的值域只有
对于
设
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 5e3 + 10, p = 998244353;
inline ll read(){
ll x = 0; char c = getchar();
while(c < '0' || c > '9') c = getchar();
while(c >= '0' && c <= '9'){x = (x << 3) + (x << 1) + (c - '0'); c = getchar();}
return x;
}
ll n, a[MAXN], f[MAXN * 2], g[3][MAXN * 2], ans, bas[MAXN];
int main(){
n = read();
bas[0] = 1;
for(int i = 1; i <= n; i++)
a[i] = read(), bas[i] = bas[i - 1] * 2 % p;
sort(a + 1, a + n + 1);
f[0] = g[0][0] = 1;
for(int i = 1; i <= n; i++){
ll sum1 = 0, sum2 = 0;
for(int j = 0; j <= a[i]; j++)
sum1 = (sum1 + f[j]) % p;
for(int j = 0; j <= a[i]; j++)
sum2 = (sum2 + g[0][j] + g[1][j]) % p;
ans = (ans - sum1 + sum2) % p;
ans = (ans + p) % p;
for(int j = 2 * a[n]; j >= a[i]; j--)
f[j] = (f[j] + f[j - a[i]]) % p;
for(int j = 2 * a[n]; j >= a[i]; j--){
g[1][j] = (g[1][j] + g[0][j - a[i]]);
g[2][j] = (g[2][j] + g[1][j - a[i]]);
}
}
ans = (ans + bas[n] - n - (n - 1) * n / 2 - 1) % p;
ans = (ans + p) % p;
cout << ans;
return 0;
}