提交时间:2023-12-02 10:31:20

运行 ID: 113451

#include <bits/stdc++.h> using namespace std; int a[35] , dp[135]; int sum; int main() { int n; cin >> n; for(int i = 0;i <0 n;i++) { cin >> a[i]; sum += a[i]; } for(int i = a[0];i <= sum;i++) dp[i] = a[0]; sort(a + 1 , a + n + 1); int sum1 = sum / 2; for(int i = 1;i < n;i++) { for(int j = sum;j >= a[i];j--) { if(j - a[i] >= 0) dp[j] = max(dp[j] , dp[j - a[i]] + a[i]); } } return 0; }