HDU1171(01背包)
来源:互联网 发布:网络信息安全办公室 编辑:程序博客网 时间:2024/05/31 19:13
Big Event in HDU
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 33311 Accepted Submission(s): 11596
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 kinds of facilities (different value, different kinds).
Input
Input contains multiple test cases. Each test case starts with a number N . The next N lines contain an integer V and an integer Meach. 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
Author
lcy
最简单的01背包 dp[j]=max(dp[j],dp[j-val[i]]+val[i]) dp【j】里存的是最接近j的取法的和
#include "cstring"#include "cstdio"#include "iostream"using namespace std;int max(int a,int b){ if(a>b) return a; else return b;}int val[250002];int dp[250002];int main(){ int n; while(~scanf("%d",&n)&&n>0) { int sum=0; int m=1; for(int i=1;i<=n;i++) { int a,b; scanf("%d%d",&a,&b); while(b--) { sum+=a; val[m++]=a; } } memset(dp,0,sizeof(dp)); for(int i=1;i<m;i++) { for(int j=sum/2;j>=val[i];j--) { dp[j]=max(dp[j],dp[j-val[i]]+val[i]); } } printf("%d %d\n",sum-dp[sum/2],dp[sum/2]); }}
- HDU1171(01背包)
- hdu1171-01背包
- HDU1171--01背包
- hdu1171 01背包
- hdu1171 01背包
- hdu1171 01背包 | 多重背包
- hdu1171 转化01背包,组合
- hdu1171(01背包变形)
- hdu1171(01背包问题)
- HDU1171:Big Event in HDU(01背包)
- hdu1171 Big Event in HDU 01-背包
- hdu1171 Big Event in HDU 01背包
- HDU1171 一维01背包DP
- hdu1171 Big Event in HDU --01背包
- HDU1171:Big Event in HDU(01背包)
- HDU1171--Big Event in HDU--01背包,多重背包
- hdu1171多重背包
- hdu1171多重背包
- jsonp 跨站的理解
- javascript用$代替document.getElementById()方法
- oracle SELECT INTO 和 INSERT INTO SELECT 两种表复制语句详解
- Codeforces 660A Co-prime Array 【水题】
- 【c语言】有n个整数,使前面各数顺序向后移m个位置,最后m个数变成最前面m个数
- HDU1171(01背包)
- (2)Java设计模式-抽象工厂方法模式(Abstract Factory)
- java 树递归
- 【c语言】一个字符串,包含n个字符。将此字符串中从第m个字符开始的全部字符复制成为另一个字符串。
- 微信支付 WXPayEntryActivity的onResp(BaseResp resp)方法 跳转处理的问题
- SSL 1607 没有上司的晚会 树形dp
- sleep()方法和yield()方法的区别
- poj_1236_Network of Schools
- java8新语法学习