T4 polygon
n\le3
显然任取
n\le20
直接暴力枚举每一个集合并判断是否合法即可,一共有
n\le500 ,\max\le100
枚举最长的木棍,该木棍必须选择,然后需要从长度不超过该木棍的集合中选出若干木棍,使得这些木棍的长度和大于最长的木棍即可,然后统计方案数,容易发现这是一个背包问题。
具体的,先对输入的数组从小到大排序,枚举
令
与
由于
n\le5000 ,\max\le5000
当枚举到
此时
std
#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 10;
const int mod = 998244353;
int n, a[maxn], dp[maxn], ans;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
sort(a + 1, a + 1 + n);
dp[0] = 1;
for (int i = 1, pw = 1; i <= n; i++, (pw *= 2) %= mod) {
(ans += pw) %= mod;
for (int j = a[i]; j >= 0; j--) (ans += (-dp[j] + mod)) %= mod;
for (int j = a[n]; j >= a[i]; j--) (dp[j] += dp[j - a[i]]) %= mod;
}
printf("%d\n", ans);
return 0;
}