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)
Total Submission(s): 34556 Accepted Submission(s): 11986
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).
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.
2
10 1
20 1
3
10 1
20 2
30 1
-1
20 10
40 40
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int a[5005],dp[300000];
int main()
{
int sum,n,v,m,tot;
while(~scanf("%d",&n)&&n>0)
{
tot=0;
sum=0;
for(int i=0;i<n;i++)
{
scanf("%d%d",&v,&m);
for(int j=0;j<m;j++)
{
a[++tot]=v;
sum+=v;
}
}
memset(dp,0,sizeof(dp));
for(int i=1;i<=tot;i++)
for(int j=sum/2;j>=a[i];j--)
{
dp[j]=max(dp[j],dp[j-a[i]]+a[i]);
}
int a=dp[sum/2];
int b=sum-a;
if(a<b)
swap(a,b);
printf("%d %d\n",a,b); }
return 0;
}
hdu1171 Big Event in HDU(01背包) 2016-05-28 16:32 75人阅读 评论(0) 收藏的更多相关文章
- one recursive approach for 3, hdu 1016 (with an improved version) , permutations, N-Queens puzzle 分类: hdoj 2015-07-19 16:49 86人阅读 评论(0) 收藏
one recursive approach to solve hdu 1016, list all permutations, solve N-Queens puzzle. reference: t ...
- hdu 1052 (greedy algorithm) 分类: hdoj 2015-06-18 16:49 35人阅读 评论(0) 收藏
thanks to http://acm.hdu.edu.cn/discuss/problem/post/reply.php?action=support&postid=19638&m ...
- hdu 1503, LCS variants, find a LCS, not just the length, backtrack to find LCS, no extra markup 分类: hdoj 2015-07-18 16:24 139人阅读 评论(0) 收藏
a typical variant of LCS algo. the key point here is, the dp[][] array contains enough message to de ...
- Improving the GPA 分类: 贪心 HDU 比赛 2015-08-08 16:12 11人阅读 评论(0) 收藏
Improving the GPA Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- Task schedule 分类: 比赛 HDU 查找 2015-08-08 16:00 2人阅读 评论(0) 收藏
Task schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- hdu 1034 (preprocess optimization, property of division to avoid if, decreasing order process) 分类: hdoj 2015-06-16 13:32 39人阅读 评论(0) 收藏
IMO, version 1 better than version 2, version 2 better than version 3. make some preprocess to make ...
- Hdu 1010 Tempter of the Bone 分类: Translation Mode 2014-08-04 16:11 82人阅读 评论(0) 收藏
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- HDU 1002 分类: ACM 2015-06-18 23:03 9人阅读 评论(0) 收藏
昨天做的那题其实和大整数相加类似.记得当初我大一寒假就卡在这1002题上,结果之后就再也没写题... 到今天终于把大整数相加写了一遍. 不过写的很繁琐,抽时间改进一下写简洁一点. #include&l ...
- HDU 2100 分类: ACM 2015-06-17 23:49 15人阅读 评论(0) 收藏
Lovekey Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
随机推荐
- webpack前端模块加载工具
最近在看许多React的资料,发现了大部分的项目都是用webpack行模块化管理的工具.这次也是借着写了一个React-Todos的小应用,对webPack最基本实用的功能体验了一番,顺带做个小记录. ...
- 首届阿里巴巴在线技术峰会,9位大V演讲整理!
https://yq.aliyun.com/articles/57826 感谢参加阿里巴巴在线技术峰会.7月19日的3场专家分享:Blink.Docker.电商互动:7月20日的云数据库十大经典案 例 ...
- 如何获取某个网站的favicon.ico
http://moco.imooc.com/player/report.html 今天看到这个网站上,左侧的小图片挺好看的,想弄下来,检查源码,也没有看到 <head> <meta ...
- thymeleaf从session中获取数据
<input th:value="${session.value1}" />
- jquery获取input file的文件名,具有兼容性
var str=$(this).val();var arr=str.split('\\');//注split可以用字符或字符串分割var fileName=arr[arr.length-1];//这就 ...
- 42. Trapping Rain Water (Array,stack; DP)
Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...
- day9:vcp考试
Q161. An administrator wants to select a Host Power Management Policy for an ESXi 6.x host that will ...
- sqserver2008触发器
@参考博文 先上代码 先建个表用于测试 CREATE TRIGGER INSERT_forbidden on s after INSERT AS BEGIN RAISERROR(,) ROLLBACK ...
- IIS 访问不了,IIS有问题,IIS右击浏览没反应
查看是否是下面的问题 web服务扩展中,下面三项设置为 “允许” CGI扩展 ISAPI扩展 Active Server Pages
- [leetcode]117. Populating Next Right Pointers in Each NodeII用next填充同层相邻节点
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *nex ...