P8742 [蓝桥杯 2021 省 AB] 砝码称重 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
const int N = 2e5+10;
int a[N],w[N];
signed main()
{
std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n;cin>>n;
for(int i=1;i<=n;i++)cin>>w[i];
bitset<100010>f;
f[0]=1;
for(int i=1;i<=n;i++)
{
f|=f<<w[i];
}
for(int i=1;i<=n;i++)
{
f|=f>>w[i];
}
cout<<f.count()-1;
return 0;
}