提交时间:2023-12-02 11:10:42
运行 ID: 113588
#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 < n;i++) { cin >> a[i]; sum += a[i]; } int sum1 = sum / 2; for(int i = a[0];i <= sum1;i++) dp[i] = a[0]; sort(a, a + n); for(int i = 1;i < n;i++) { for(int j = sum1;j >= a[i];j--) { if(j - a[i] >= 0) dp[j] = max(dp[j] , dp[j - a[i]] + a[i]); } } cout << sum - 2 * dp[sum1]; return 0; }