HDU 1171.Big Event in HDU【01背包】【5月26】
来源:互联网 发布:ubuntu开机黑屏 编辑:程序博客网 时间:2024/06/07 02:01
Big Event in HDU
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 34498 Accepted Submission(s): 11964
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).
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.
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
210 120 1310 1 20 230 1-1
Sample Output
20 1040 40
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int MAX = 250005;int val[MAX], DP[MAX];int N, v, m, l, sum;int main(){ while(scanf("%d", &N) != EOF) { if(N < 1) break; memset(DP, 0, sizeof(DP)); sum = l = 0; while(N--) { scanf("%d %d", &v, &m); sum += v*m; while(m--) val[l++] = v; } for(int i = 0;i < l; ++i) for(int j = sum/2;j >= val[i]; --j) DP[j] = max(DP[j], DP[j-val[i]]+val[i]); cout << sum-DP[sum/2] <<" "<< DP[sum/2] << endl; } return 0;}
0 0
- HDU 1171.Big Event in HDU【01背包】【5月26】
- HDU1171:Big Event in HDU(01背包)
- hdu1171 Big Event in HDU 01-背包
- hdu1171 Big Event in HDU 01背包
- Big Event in HDU (HDU_1171) 01背包
- hdu1171 Big Event in HDU --01背包
- HDU1171:Big Event in HDU(01背包)
- Big Event in HDU 背包
- hdu 1171 Big Event in HDU(01背包&多重背包)
- HDU Big Event in HDU - 多重背包
- [HDU 1171 Big Event in HDU]背包
- hdu 1171 Big Event in HDU 01背包
- HDU--航但--1171--Big Event in HDU--01背包
- Big Event in HDU - HDU 1171 01背包
- HDU 1171 Big Event in HDU(01背包)
- HDU 1171 Big Event in HDU(01背包)
- HDU 1171 Big Event in HDU(01背包)
- hdu 1171 Big Event in HDU(01背包)
- 【图像处理】Haar Adaboost 检测自定义目标(视频车辆检测算法代码)
- PyQt5:建立对话框(1)
- ROC曲线以及评估指标F1-Score, recall, precision-整理版
- android style
- haartraining训练生成xml过程
- HDU 1171.Big Event in HDU【01背包】【5月26】
- mina第一篇:基本demo实现
- android Gson解析
- linux 自行安装lanmp
- [POJ 3040] Allowance (贪心)
- Cocos2dx 3.x移植Android及打包
- Xcode 7 缺少 *.dylib库的解决方法
- 最佳A*算法【转】
- 【转载】dubbo学习