标签:
Description
Input
Output
Sample Input
Sample Output
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; int dp[250005]; int n; int w[50005]; int main() { while(scanf("%d",&n)!=EOF&&n>=0) { memset(dp,0,sizeof(dp)); int sum=0; int v,num; int cnt=0; for(int i=0;i<n;i++) { scanf("%d%d",&v,&num); sum+=num*v; while(num)//将相同的设备分开 { w[cnt++]=v; num--; } } for(int i=0;i<cnt;i++) for(int j=sum/2;j>=w[i];j--) dp[j]=max(dp[j],dp[j-w[i]]+w[i]); int ans=max(dp[sum/2],sum-dp[sum/2]); printf("%d %d\n",ans,sum-ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/program-ccc/p/5212294.html