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 ...
随机推荐
- Where is the python library installed?
configure: error: Could not link test program to Python. Maybe the main Python library has been inst ...
- VS2010编译错误 LNK 2019 unresolved external symbol错误解决办法
Link错误有很多种,主要是没有在连接中加入lib文件路径,或者lib配置正确,传参错误 一个solution里面多个project之间引用其他project函数会出现这个错误,由于包含了头文件而没处 ...
- chapter9_2 管道与过滤器
一个关于协同程序的经典示例就是“生产者-消费者”的问题. 一个不断产生值,一个不断消费这些值.比如: function producer() while true do local x = io.re ...
- android代码格式化方法小结
转载:http://blog.csdn.net/androidzhaoxiaogang/article/details/7692526 Download the android-formatting. ...
- HDU 5775 Bubble Sort
对于一个数,可以记录3个位置:初始位置,终点位置,最右边的位置. 初始位置和终点位置容易计算.最多边的位置即为初始状态下该数的位置+该数之后还有多少数比该数小. 三个位置中的min即为leftpos, ...
- point类型·
指针的类型 不同类型的指针,从内存需求的观点来说,没有什么不同!他们三个都需要足够的内存来繁殖一个机器地址,"指向不同类型之各指针"之间的差异,既不在其指针表示法不同,也不再其内容 ...
- Software Version
Software Version Time Limit : 3000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) To ...
- ubuntu 软件管理
软件安装管理 安装软件 sudo apt-get install **** 检索软件 sudo apt-cache search **** 更新源 sudo apt-get update **** ...
- oracle的exp和imp命令的使用【转载】
oracle的exp和imp命令的使用 我们通常要对ORACLE的数据进行导入,导出,在没有expdb,impdb以前(10G以前),我们都是使用exp 导出,imp命令来实现导入. 打开 ...
- PHP之音乐ID3扩展
不知道你有没有这样的经历,一些从网上下载的MP3音乐,文件名明明是01.02这样的序号,但播放时却能显示出歌曲的正确名称来,是不是有点奇妙? 这其实都是ID3在暗中相助 ID3,一般是位于一个mp3文 ...