u1s1我一开始理解错了题
然后基本就相当于一个背包dp了

#include <bits/stdc++.h>
using namespace std;

int n,tot,a[305],f[100005],g[100005],ans;

int main() {
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
        tot+=a[i];
    }
    sort(a+1,a+n+1);
    reverse(a+1,a+n+1);
    f[0]=1;
    for(int i=1;i<=n;i++) {
        for(int j=tot;j>=a[i];--j) {
            f[j]|=f[j-a[i]];
            if(j-a[i]<=tot/2) g[j]|=f[j-a[i]];
        }
    }
    for(int i=(tot+1)/2;i<=tot;i++) if(g[i]) ans=i;
    cout<<ans<<endl;
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-07
  • 2021-12-10
  • 2021-11-04
  • 2021-07-30
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-21
  • 2022-02-26
  • 2021-10-08
  • 2021-12-22
  • 2022-01-27
  • 2021-08-07
  • 2022-01-22
相关资源
相似解决方案