文章
17
粉丝
177
获赞
2
访问
118.3k
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
vector<int> dp(500001, 0);
int times[20];
int sum = 0, n;
cin >> n;
for (int i = 0; i < n;i++)
{
cin >> times[i];
sum += times[i];
}
int bag_cap = sum / 2;
for (int i = 0;i < n;i++)
for (int j = bag_cap; j >= times[i];j--)
{
dp[j] = max(dp[j], dp[j - times[i]] + times[i]);
}
cout << abs(dp[bag_cap] - (sum - dp[bag_cap])) << endl;
}
登录后发布评论
暂无评论,来抢沙发