HDU 1171 Big Event in HDU (多重背包)
2016-08-12 16:38
253 查看
Big Event in HDU
Time Limit : 10000/5000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 62 Accepted Submission(s) : 26
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
Nowadays, we all know that Computer College is the biggest department in HDU. But, maybe you don't know that Computer College had ever been split into Computer College and Software College in 2002.The splitting is absolutely a big event in HDU! At the same time, it is a trouble thing too. All facilities must go halves. First, all facilities are assessed, and two facilities are thought to be same if they have the same value. It is assumed that there is
N (0<N<1000) kinds of facilities (different value, different kinds).
Input
Input contains multiple test cases. Each test case starts with a number N (0 < N <= 50 -- the total number of different facilities). The next N lines contain an integer V (0<V<=50 --value of facility) and an integer M (0<M<=100 --correspondingnumber of the facilities) each. You can assume that all V are different.
A test case starting with a negative integer terminates input and this test case is not to be processed.
Output
For each case, print one line containing two integers A and B which denote the value of Computer College and Software College will get respectively. A and B should be as equal as possible. At the same time, you should guarantee that A isnot less than B.
Sample Input
2 10 1 20 1 3 10 1 20 2 30 1 -1
Sample Output
20 10 40 40 分成两份尽可能一样大的部分。那么就相当于将背包容量变成所有东西总价值的一半,求尽可能大的价值。 AC代码:
#include<iostream> #include<vector> #include<cstdio> #include<algorithm> #include<map> #include<set> #include<stack> #include<cmath> #include<string.h> #include<queue> using namespace std; int v,dp[266666]; void ZOP(int cost,int wei) { for(int i=v;i>=cost;i--) dp[i]=max(dp[i],dp[i-cost]+wei); } void CP(int cost,int wei) { for(int i=cost;i<=v;i++) dp[i]=max(dp[i],dp[i-cost]+wei); } void MP(int cost,int wei,int cnt) { if(cost*cnt>=v) { CP(cost,wei); return; } else { int k=1; while(k<cnt) { ZOP(k*cost,k*wei); cnt-=k; k<<=1; } ZOP(cnt*cost,cnt*wei); } } int main() { int t; while(cin>>t) { if(t<0) break; memset(dp,0,sizeof(dp)); int sum=0; int a[1001],b[1001]; for(int i=1;i<=t;i++) { cin>>a[i]>>b[i]; sum+=a[i]*b[i]; } v=sum; for(int i=1;i<=t;i++) { if(b[i]==1) ZOP(a[i],a[i]); else MP(a[i],a[i],b[i]); } v/=2; while(dp[v]!=v) v--; cout<<sum-dp[v]<<" "<<dp[v]<<endl; } return 0; }
相关文章推荐
- hdu 1171 Big Event in HDU(多重背包+二进制优化)
- Hdu 1171 Big Event in HDU (多重背包)
- HDU 1171 Big Event in HDU 动态规划多重背包
- HDU 1171 Big Event in HDU【多重背包】
- hdu 1171 Big Event in HDU(母函数|多重背包)
- HDOJ-1171 Big Event in HDU(多重背包/母函数)
- HDU 1171 Big Event in HDU (多重背包)
- hdu 1171 Big Event in HDU 多重背包
- hdu——1171——Big Event in HDU(多重背包)
- hdoj 1171 Big Event in HDU(背包dp+母函数)
- HDU-1171 Big Event in HDU 背包
- HDU/HDOJ 1171 Big Event in HDU 01背包、多重背包、母函数
- HDU 1171 Big Event in HDU (多重bool背包) /(01背包)
- HDU 1171 Big Event in HDU 多重背包 数分一半
- HDU 1171 Big Event in HDU(背包)
- HDU 1171 Big Event in HDU(多重背包)
- hdu 1171 Big Event in HDU(多重背包+二进制优化)
- hdu 1171 Big Event in HDU(多重背包可行性)
- 杭电1171 Big Event in HDU(母函数+多重背包解法)
- HDU 1171 Big Event in HDU【多重背包||母函数】