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 ...
随机推荐
- Mysql: 开启慢查询日志[ERROR] unknown variable 'log-slow-queries'处理办法
参考: http://www.dataguru.cn/thread-305503-1-1.html # slow query log qjp 20160921 # mysql5.6版本以上,取消了参数 ...
- GO 语言队列实现
队列(queue)是只允许在一端进行插入操作,而在另一端进行删除操作的线性表. 队列是一种先进先出的t(First In First Out)的线性表,简称FIFO.允许插入的一端为队尾,允许删除的一 ...
- Python Internet 模块
Python Internet 模块 以下列出了 Python 网络编程的一些重要模块: 协议 功能用处 端口号 Python 模块 HTTP 网页访问 80 httplib, urllib, xml ...
- poj 3625 (最小生成树算法)
Building Roads Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12203 Accepted: 3448 D ...
- TTTTTTTTTTTTTTTTT CF #182 div1 B floyd
题意: 有 n(3≤n≤100) 个站点,当第一次到达站点 u 的时候会增加寿命 au(1≤au≤103),题目给了 n 个站点的二位空间坐标,每两个站点之间的距离为曼哈顿距离(dis(i, j)=| ...
- 1003: [ZJOI2006]物流运输
就我一开始写状压的吗? 调不过 后来发现(直接搜索)直接最短路就行了-- \(f[i]\)表示前\(i\)天最少需要多少 \(f[i] = min(f[j] + dis(j + 1, i))\) 然后 ...
- Makefile文件试错
1成功: src = $(wildcard ./*cpp) obj = $(patsubst %.cpp,%.o ,$(src)) target = test $(target) : $(obj) g ...
- nopCommerce4.10学习笔记——入门
1.下载 千万不要去GitHub上下载,千万不要去GitHub上下载,千万不要去GitHub上下载!!!,重要的事情说3遍,说多了都是泪,你懂的 下载网址:https://www.nopcommerc ...
- TCP如何保证可靠传输
TCP 协议如何保证可靠传输 一.综述 1.确认和重传:接收方收到报文就会确认,发送方发送一段时间后没有收到确认就重传. 2.数据校验 3.数据合理分片和排序: UDP:IP数据报大于1500字节 ...
- 捕获有问题的SQL