Big Event in HDU

 
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1139 Accepted Submission(s): 444
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
 

Author
lcy

这是一个多重背包的题目(将物品的原价值即为放入背包中物品的价值与花费,因为当不超过背包容量且价值之和最大时,即为不超过背包容量且花费之和最大(花费最接近背包容量),即为这些物品的原价值之和最接近背包容量。此处将物品总价值的一半看为背包容量即可。

这里有一个我见过的最诡异的八阿哥。。。汗。。。

这道题是以负数作为输入的结束标志的,而不只局限于-1, 被惯性思维坑了。。。。

代码:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int MAXN=;
const int inf=;
int v[MAXN];
int dp[MAXN];
int num[];
int main()
{
//freopen("data.in","r",stdin);
std::ios::sync_with_stdio(false);
std::cin.tie();
int n;
int sum;
int cc;
while(cin>>n&&n>=){
sum=;
memset(dp,,sizeof(dp));
for(int i=;i<n;i++){
cin>>v[i]>>num[i];
sum+=(v[i]*num[i]);
}
cc=sum/;
for(int i=;i<n;i++){
for(int k=;k<num[i];k++){
for(int j=cc;j>=v[i];j--){
dp[j]=max(dp[j],dp[j-v[i]]+v[i]);
}
}
}
cout<<sum-dp[cc]<<" "<<dp[cc]<<endl;
}
}

HDU1171--Big Event in HDU(多重背包)的更多相关文章

  1. hdu1171 Big Event in HDU(多重背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=1171 多重背包题目不难,但是有些点不能漏或错. #include<iostream> #includ ...

  2. HDU 1171 Big Event in HDU 多重背包二进制优化

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1171 Big Event in HDU Time Limit: 10000/5000 MS (Jav ...

  3. HDU - 1171 Big Event in HDU 多重背包

    B - Big Event in HDU Nowadays, we all know that Computer College is the biggest department in HDU. B ...

  4. HDU 1171 Big Event in HDU (多重背包变形)

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  5. HDU1171:Big Event in HDU(多重背包分析)

    通过分析,要使A>=B并且差值最小.所以只要使sum/2的容量下,B最大就Ok了 #include<iostream> #include<cstdio> #include ...

  6. HDU-1171 Big Event in HDU(生成函数/背包dp)

    题意 给出物品种类,物品单价,每种物品的数量,尽可能把其分成价值相等的两部分. 思路 背包的思路显然是用一半总价值当作背包容量. 生成函数则是构造形如$1+x^{w[i]}+x^{2*w[i]}+.. ...

  7. hdu1171 Big Event in HDU(01背包) 2016-05-28 16:32 75人阅读 评论(0) 收藏

    Big Event in HDU Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  8. hdu1171 Big Event in HDU 01-背包

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171 Problem ...

  9. HUD 1171 Big Event in HDU(01背包)

    Big Event in HDU Problem Description Nowadays, we all know that Computer College is the biggest depa ...

  10. HDU 1171 Big Event in HDU dp背包

    Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s ...

随机推荐

  1. webapi中的自定义路由约束

    Custom Route Constraints You can create custom route constraints by implementing the IHttpRouteConst ...

  2. 如何在Excel中少犯二(I)

    作者:何明科链接:https://zhuanlan.zhihu.com/p/23472480来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 收到不少建议,要求开知乎Li ...

  3. php基础的第一天 任务点滴,event对象方法概括 ing....

    day1 任务 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <t ...

  4. A - 小彭玉的扫荡食堂计划

    A - 小彭玉的扫荡食堂计划 Time Limit: 20000/10000MS (Java/Others)    Memory Limit: 128000/64000KB (Java/Others) ...

  5. Python 学习笔记9

    梦想和我只有一层纸的距离. 接着看Python类:http://www.pythondoc.com/pythontutorial3/classes.html

  6. js上拉跳转原理

    今天遇到一个需要上拉跳转的地方,其原理跟上拉加载有点类似,代码如下 window.onscroll = function(){ if(getScrollTop() + getClientHeight( ...

  7. 2016-11-10linux

    ---恢复内容开始---  新建用户natasha,uid为88,gid为6,备注信息为"master"   修改natasha用户的家目录为/Natasha    查看用户信息配 ...

  8. oracle 同义词

    同义词概念 Oracle的同义词(synonyms)从字面上理解就是别名的意思,和视图的功能类似,就是一种映射关系.它可以节省大量的数据库空间,对不同用户的操作同一张表没有多少差别;它扩展了数据库的使 ...

  9. 浅析PageRank算法

    很早就对Google的PageRank算法很感兴趣,但一直没有深究,只有个轮廓性的概念.前几天趁团队outing的机会,在动车上看了一些相关的资料(PS:在动车上看看书真是一种享受),趁热打铁,将所看 ...

  10. As3.0 Interface 与类的使用

    来源:http://blog.sina.com.cn/s/blog_4d65c19e0100bfkb.html 抽象类:又叫抽象基类:可以包含一般类所包含的所有特性,例如,字段,属性,方法,抽象类不能 ...