HDU 1171 Big Event in HDU(01背包)
来源:互联网 发布:各国的创世神话 知乎 编辑:程序博客网 时间:2024/06/05 22:31
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171点击打开链接
Big Event in HDU
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 43915 Accepted Submission(s): 15105
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
将背包容量变为一般 然后基础01背包
#include<bits/stdc++.h>#define maxn 250010using namespace std;int a[maxn];int dp[maxn];int main(){ int n; int sum=0; while(cin >> n&&n>0) { memset(dp,0,sizeof(dp)); sum=0; int temp=1; for(int i=1;i<=n;i++) { int value; int num; scanf("%d",&value); scanf("%d",&num); sum+=(value*num); int j; for(j=1;j<=num;j<<=1) { a[temp++]=j*value; num-=j; } if(num>0) a[temp++]=num*value; } int summ=sum/2; temp--; sort(a+1,a+temp+1); for(int i=1;i<=temp;i++) for(int j=summ;j>=a[i];j--) dp[j]=max(dp[j],dp[j-a[i]]+a[i]); cout << sum-dp[summ] << " " << dp[summ] << endl; }}
阅读全文
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背包
- java中的IO File类的用法详解加代码演示
- 使用ATtiny85单片机驱动四个RGB LED指示灯
- Ubuntu 16.04下安装以太坊编译环境以及设置合约功能(支持geth 1.6以及solc 0.4.16版本以上)
- invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific
- Java中String.format()使用
- HDU 1171 Big Event in HDU(01背包)
- Statement、PreparedStatement和CallableStatement
- Struts2 Action中调用get***命名方法,并且返回json,执行出错
- mysql 提示表不存在的解决方法error: 1146: Table doesn't exist
- shell脚本搭建容器云(-)
- ortp库使用入门
- AOP面向切面编程
- JAVA--浅谈java中间缓存变量机制---(j++和++j的区别)
- python学习——tuple