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)
Total Submission(s): 57986 Accepted Submission(s): 19484
Problem Description
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
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
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
-
Sample Output
题目大意与分析
给出一堆东西的重量和个数,要尽可能的将物品分成重量接近的两堆A和B,且A的重量不小于B
求以sum/2为容量的背包即可,求出来的值就是B sum减去B就是A
代码
#include <bits/stdc++.h>
using namespace std; int val[];
int dp[]; int main()
{
int n,i,j,a,b,l,sum;
while(~scanf("%d",&n),n>)
{
memset(val,,sizeof(val));
memset(dp,,sizeof(dp));
l = ;
sum = ;
for(i = ;i<n;i++)
{
scanf("%d%d",&a,&b);
while(b--)
{
val[l++] = a;
sum+=a;
}
}
for(i = ;i<l;i++)
{
for(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 (动态规划、01背包)的更多相关文章
- 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背包/求两堆数分别求和以后的差最小】
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- 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 ...
- 【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(01背包)
题目链接 题意:给出n个物品的价值v,每个物品有m个,设总价值为sum,求a,b.a+b=sum,且a尽可能接近b,a>=b. 题解:01背包. #include <bits/stdc++ ...
- HDU 1171 Big Event in HDU【01背包】
题意:给出n个物品的价值和数目,将这一堆物品分给A,B,问怎样分使得两者的价值最接近,且A的要多于B 第一次做的时候,没有思路---@_@ 因为需要A,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 ...
- HDU 1171 Big Event in HDU dp背包
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s ...
随机推荐
- Python 面向对象Ⅳ
类的继承 面向对象的编程带来的主要好处之一是代码的重用,实现这种重用的方法之一是通过继承机制. 通过继承创建的新类称为子类或派生类,被继承的类称为基类.父类或超类. 继承语法 在python中继承中的 ...
- 定时任务spring task
1)spring boot 几种定时任务的实现方式:https://www.jianshu.com/p/b6809b5a0c26 2)spring-boot 定时任务之Scheduled Task:h ...
- Cobbler自动装机
preface 我们之前批量安装操作系统的时候都是采用pxe来安装,pxe也是通过网络安装操作系统的,但是PXE依赖于DHCP,HTTP/TFTP,kicstart等支持.安装流程如下所示: 对于上面 ...
- jQuery_插入操作
jQuery的插入方法有很多,有内部插入,也有外部插入,每个插入方式里面还有很多种,本文一一介绍,注释在代码里,直接上代码: 代码: <!DOCTYPE html> <html> ...
- Python 标准库、第三方库
Python 标准库.第三方库 Python数据工具箱涵盖从数据源到数据可视化的完整流程中涉及到的常用库.函数和外部工具.其中既有Python内置函数和标准库,又有第三方库和工具.这些库可用于文件读写 ...
- JS框架_(Esign.js)仿信用卡电子签名特效
百度云盘 传送门 密码:l60w 电子签名特效效果: <!DOCTYPE html> <html> <head lang="en"> <m ...
- RedisTemplate zSet的使用, 根据点赞排序,和创建时间排序2种方式
使用Redis 对问题下的回答按点赞数排序的思路; 1根据问题id查出所有的回答列表; 2吧回答的ids添加到zset1中; key为id,value为赞的数量;(用于点赞排行); //批量添加 Lo ...
- VS2015 ASP.NET MVC5 EntityFramework6 Oracle 环境篇
//来源:https://www.cnblogs.com/lauer0246/articles/9576940.html Asp.Net MVC EF各版本区别 2009年發行ASP.NET MVC ...
- Java连接MQTT服务-wss方式
特别提示:本人博客部分有参考网络其他博客,但均是本人亲手编写过并验证通过.如发现博客有错误,请及时提出以免误导其他人,谢谢!欢迎转载,但记得标明文章出处:http://www.cnblogs.com/ ...
- Git:本地项目与远程仓库的git/clone
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/qq_40197828/article/details/79283278 初识Git命令行将本地项 ...