HDU1171--Big Event in HDU(多重背包)
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 |
Sample Output
20 10 |
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(多重背包)的更多相关文章
- hdu1171 Big Event in HDU(多重背包)
http://acm.hdu.edu.cn/showproblem.php?pid=1171 多重背包题目不难,但是有些点不能漏或错. #include<iostream> #includ ...
- 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 ...
- 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 ...
- HDU 1171 Big Event in HDU (多重背包变形)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU1171:Big Event in HDU(多重背包分析)
通过分析,要使A>=B并且差值最小.所以只要使sum/2的容量下,B最大就Ok了 #include<iostream> #include<cstdio> #include ...
- HDU-1171 Big Event in HDU(生成函数/背包dp)
题意 给出物品种类,物品单价,每种物品的数量,尽可能把其分成价值相等的两部分. 思路 背包的思路显然是用一半总价值当作背包容量. 生成函数则是构造形如$1+x^{w[i]}+x^{2*w[i]}+.. ...
- 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 ...
- hdu1171 Big Event in HDU 01-背包
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171 Problem ...
- HUD 1171 Big Event in HDU(01背包)
Big Event in HDU Problem Description Nowadays, we all know that Computer College is the biggest depa ...
- HDU 1171 Big Event in HDU dp背包
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s ...
随机推荐
- 第二次冲刺spring会议(第一次会议)
[例会时间]2014/5/4 21:15 [例会地点]9#446 [例会形式]轮流发言 [例会主持]马翔 [例会记录]兰梦 小组成员:兰梦 ,马翔,李金吉,赵天,胡佳奇 内部测试版发布时间5月11日 ...
- Openjudge-计算概论(A)-判断闰年
描述: 判断某年是否是闰年.输入输入只有一行,包含一个整数a(0 < a < 3000)输出一行,如果公元a年是闰年输出Y,否则输出N样例输入 2006 样例输出 N 提示:公历纪年法中, ...
- PHP CURL 代理发送数据
$session = curl_init($request); curl_setopt ($session, CURLOPT_PROXY, $proxy); curl_setopt ($session ...
- submit提交表单后,不刷新当前页面
<form method="get" target="test" action="a.html"> <input type ...
- AltiumDesigner14绘制四层板设置
1,快捷键(O+K)进入板层设置界面: 2,选择AddLayer,里边有两个选项(add layer(添加信号层)||add internal plane(增加平面)) 四层板的话一般层次的划分是t ...
- 关于UIFont和计算字符串的高度和宽度
转自:http://i.cnblogs.com/EditPosts.aspx?opt=1 1.创建方法:+ fontWithName:size:- fontWithSize:2.创建系统字体:+ sy ...
- js添加div
有这样一段div布局 <div class="clearfix"> <p class="left c"> <s ...
- swift UILable的用法
- 《JavaScript高级程序设计》读书笔记 ---基本概念小结
ECMAScript 中的基本数据类型包括Undefined.Null.Boolean.Number 和String. 与其他语言不同,ECMScript 没有为整数和浮点数值分别定义不同的数据 ...
- Chapter 2 Open Book——5
I was relieved that I had the desk to myself, that Edward was absent. 我能一个人一张桌子很开心,就因为Edward 没来. I t ...