hdu——1171——Big Event in HDU(多重背包)
来源:互联网 发布:灯光矩阵什么意思 编辑:程序博客网 时间:2024/05/21 06:26
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 --corresponding number 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 is not less than B.
Sample Input
2
10 1
20 1
3
10 1
20 2
30 1
-1
Sample Output
20 10
40 40
把总体积分成两部分
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 --corresponding number 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 is not less than B.
Sample Input
2
10 1
20 1
3
10 1
20 2
30 1
-1
Sample Output
20 10
40 40
把总体积分成两部分
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main(){int n;int v[60],w[60];int dp[250005];while(scanf("%d",&n)!=EOF){if(n<=0)return 0;memset(dp,0,sizeof(dp));int sum=0;for(int i=0;i<n;i++){cin>>v[i]>>w[i];sum+=v[i]*w[i];}int ztj=sum;sum/=2;for(int i=0;i<n;i++){for(int j=0;j<w[i];j++){for(int k=sum;k>=v[i];k-=v[i]){dp[k]=max(dp[k],dp[k-v[i]]+v[i]);}}}if(dp[sum]>ztj-dp[sum])cout<<dp[sum]<<" "<<ztj-dp[sum]<<endl;elsecout<<ztj-dp[sum]<<" "<<dp[sum]<<endl;}return 0;}
0 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(多重背包)
- 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(多重背包)
- HDU 1171 Big Event in HDU(多重背包)
- HDU 1171 Big Event in HDU(多重背包)
- HDU 1171 Big Event in HDU(多重背包)
- Big Event in HDU (多重背包)
- hdu 1171 Big Event in HDU(01背包&多重背包)
- HDOJ题目1171Big Event in HDU(多重背包)
- HDOJ 1171 Big Event in HDU(多重背包)
- HDU Big Event in HDU - 多重背包
- 通过网页抓取github仓库的部分文件
- ASP.NET中如何在页面前端书写C#代码?
- 黑马程序员----冒泡排序和选择排序
- POJ 3243 Clever Y 解高次同余方程
- oracle客户端乱码
- hdu——1171——Big Event in HDU(多重背包)
- 管网资源管理系统排除故障分析
- C#窗体皮肤制作(一):资源图片的获取
- 你绝对没有见过的CSS用法
- Ningbo [1217] Dinner(简单题,但是注意输出,pe3遍)
- NYOJ216 A problem is easy
- 对web项目的单元测试方法
- CoreMotion可以测到的各种值
- OCSP服务流程图