HDU 1171.Big Event in HDU-动态规划0-1背包
Big Event in HDU
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 51519 Accepted Submission(s): 17609
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).
A test case starting with a negative integer terminates input and this test case is not to be processed.
10 1
20 1
3
10 1
20 2
30 1
-1
40 40
代码:
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+;
int val[N],dp[N];
int main(){
int n,a,b,len,sum;
while(~scanf("%d",&n),n>){
memset(dp,,sizeof(dp));
memset(val,,sizeof(val));
len=;sum=;
for(int i=;i<n;i++){
scanf("%d%d",&a,&b);
while(b--){
val[len++]=a;
sum+=a;
}
}
for(int i=;i<len;i++){
for(int j=sum/;j>=val[i];j--){
dp[j]=max(dp[j],dp[j-val[i]]+val[i]);
}
}
printf("%d %d\n",sum-dp[sum/],dp[sum/]);
}
return ;
}
HDU 1171.Big Event in HDU-动态规划0-1背包的更多相关文章
- 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(01背包)
题目地址:HDU 1171 还是水题. . 普通的01背包.注意数组要开大点啊. ... 代码例如以下: #include <iostream> #include <cstdio&g ...
- HDU 1171 Big Event in HDU (动态规划、01背包)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1171 Big Event in HDU (多重背包变形)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 组合数学 - 母函数的变形 --- hdu 1171:Big Event in HDU
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1171 Big Event in HDU (多重背包)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- hdu 1171 Big Event in HDU(母函数)
链接:hdu 1171 题意:这题能够理解为n种物品,每种物品的价值和数量已知,现要将总物品分为A,B两部分, 使得A,B的价值尽可能相等,且A>=B,求A,B的价值分别为多少 分析:这题能够用 ...
- 【01背包】HDU 1171 Big Event in HDU
Problem Description Nowadays, we all know that Computer College is the biggest department in HDU. Bu ...
- HDU 1171 Big Event in HDU dp背包
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s ...
- HDU 1171 Big Event in HDU 母函数
欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory ...
随机推荐
- ARC下,不显式指定任何属性关键字时,默认的关键字都有哪些
1.对应基本数据类型默认关键字是 atomic,readwrite,assign 2.对于普通的 Objective-C 对象 atomic,readwrite,strong
- 《Cracking the Coding Interview》——第8章:面向对象设计——题目2
2014-04-23 17:45 题目:假设有个呼叫中心,有接线员.经理.主管三种角色.如果接线员无法处理呼叫,就上传给经理:如果仍无法处理,则上传给主管.请用代码描述这一过程. 解法:第一眼觉得这题 ...
- PhpStorm 格式化中花括号缩进方式
格式化前: function func() { return ; } 格式化后: function func() { return ; } 在PhpStorm中的配置:File -> Setti ...
- 【非原创】tomcat 安装时出现 Failed to install Tomcat7 service
tomcat 安装时出现 Failed to install Tomcat7 service 今天在安装tomcat时提示 Failed to install Tomcat7 service了,花了大 ...
- css:hover状态改变另一个元素样式的使用
效果演示 css:hover状态改变另一个元素样式的使用 .box { width: 150px; height: 150px; background-color: #069; line-height ...
- OpenCV_1.0安装包下载
OpenCV_1.0安装包下载 点击下载
- PAT——甲级1009:Product of Polynomials;乙级1041:考试座位号;乙级1004:成绩排名
题目 1009 Product of Polynomials (25 point(s)) This time, you are supposed to find A×B where A and B a ...
- CentOS 6.3 下 vsftp搭建
环境:CentOS6.3 ftp的三种用户模式 匿名用户:vsftp默认开启匿名用户,但只允许下载不允许上传:匿名用户anonymous或ftp:匿名用户目录/var/ftp,但实际上vsftp对匿名 ...
- jsp页面提示“Multiple annotations found at this line: - The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path”解决方案
Multiple annotations found at this line: - The superclass "javax.servlet.http.HttpServlet" ...
- JDK从1.8.x升级到9.0.1后Tomcat 8.0.x不能启动
目录 描述 具体环境情况 处理办法 描述 JDK在今年9月发布后,我们项目也打算测试升级使用JDK 9.在我将JDK升级成 JDK 9.0.1后,启动tomcat失败(黑框一闪就没了).具体失败信息如 ...