标签:using bsp main iostream div can style std ios
http://acm.xidian.edu.cn/problem.php?id=1172
取和的一半,背包问题。
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; int n,w[205],dp[200005]; int main() { while(~scanf("%d",&n)) { memset(dp,0,sizeof(dp)); int sum = 0; for(int i = 1;i <= n;i++) { scanf("%d",&w[i]); sum += w[i]; } int endd = sum/2; for(int i = 1;i <= n;i++) { for(int j = endd;j >= w[i];j--) { dp[j] = max(dp[j],dp[j-w[i]]+w[i]); } } printf("%d\n",sum-dp[endd]*2); } return 0; }
标签:using bsp main iostream div can style std ios
原文地址:http://www.cnblogs.com/zhurb/p/6041293.html