HDU 1171 Big Event in HDU(01背包)
来源:互联网 发布:ubuntu卸载搜狗拼音 编辑:程序博客网 时间:2024/05/22 00:39
Big Event in HDU
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 34683 Accepted Submission(s): 12030
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
Author
lcy
代码:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 300000int dp[maxn],v[1000],m[1000];int main(){ int n; while(~scanf("%d",&n)&&n>=0) { int sum=0; for(int i=0;i<n;i++) { scanf("%d%d",&v[i],&m[i]); sum=sum+v[i]*m[i]; } memset(dp,0,sizeof(dp)); for(int i=0;i<n;i++) { for(int j=1;j<=m[i];j++) { for(int k=sum/2;k>=j*v[i];k--) { dp[k]=max(dp[k],dp[k-v[i]]+v[i]); } } } printf("%d %d\n",max(sum-dp[sum/2],dp[sum/2]),min(sum-dp[sum/2],dp[sum/2])); }}
0 0
- 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背包)
- 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背包变形)
- HDU 1171 Big Event in HDU (DP--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]背包
- HDOJ 1171 Big Event in HDU(01背包)
- 杭电1171Big Event in HDU(01背包)
- hdu 1171 Big Event in HDU 01背包
- HDU--航但--1171--Big Event in HDU--01背包
- Big Event in HDU - HDU 1171 01背包
- MySql生成.Net中Model类的存储过程
- android 打开文件的Intent及使用
- C++面试题 1-50
- 【Android基础知识】IntentService基本使用
- 控制台颜色设置
- HDU 1171 Big Event in HDU(01背包)
- Java基础知识IO流(拷贝文本文件)
- 整数哈希介绍
- 50-100
- 软件里的alpha版和beta版是什么意思?
- Android编码规范
- 堆、堆栈与数据结构中的堆
- [svn] 解决SVN冲突攻略(手册)
- 关于lex中正则表达式区分减号和负号(正后顾不可用)