HDU1171(01背包均分问题)
Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
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
A test case starting with a negative integer terminates input and this test case is not to be processed.
Output
Sample Input
Sample Output
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- using namespace std;
- int dp[];
- int n;
- int w[];
- int main()
- {
- while(scanf("%d",&n)!=EOF&&n>=)
- {
- memset(dp,,sizeof(dp));
- int sum=;
- int v,num;
- int cnt=;
- for(int i=;i<n;i++)
- {
- scanf("%d%d",&v,&num);
- sum+=num*v;
- while(num)//将相同的设备分开
- {
- w[cnt++]=v;
- num--;
- }
- }
- for(int i=;i<cnt;i++)
- for(int j=sum/;j>=w[i];j--)
- dp[j]=max(dp[j],dp[j-w[i]]+w[i]);
- int ans=max(dp[sum/],sum-dp[sum/]);
- printf("%d %d\n",ans,sum-ans);
- }
- return ;
- }
HDU1171(01背包均分问题)的更多相关文章
- UVA562(01背包均分问题)
Dividing coins Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Descriptio ...
- POJ3211(trie+01背包)
Washing Clothes Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 9384 Accepted: 2997 ...
- hihocoder 1038 01背包
#1038 : 01背包 时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 且说上一周的故事里,小Hi和小Ho费劲心思终于拿到了茫茫多的奖券!而现在,终于到了小Ho领取奖励 ...
- 1171 Big Event in HDU 01背包
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1171 题意:把商品分成两半,如不能均分,尽可能的让两个数相接近.输出结果:两个数字a,b且a>=b. ...
- poj3211Washing Clothes(字符串处理+01背包) hdu1171Big Event in HDU(01背包)
题目链接: id=3211">poj3211 hdu1171 这个题目比1711难处理的是字符串怎样处理,所以我们要想办法,自然而然就要想到用结构体存储.所以最后将全部的衣服分组,然 ...
- UVALive 4870 Roller Coaster --01背包
题意:过山车有n个区域,一个人有两个值F,D,在每个区域有两种选择: 1.睁眼: F += f[i], D += d[i] 2.闭眼: F = F , D -= K 问在D小于等于一定限度的时 ...
- POJ1112 Team Them Up![二分图染色 补图 01背包]
Team Them Up! Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7608 Accepted: 2041 S ...
- Codeforces 2016 ACM Amman Collegiate Programming Contest A. Coins(动态规划/01背包变形)
传送门 Description Hasan and Bahosain want to buy a new video game, they want to share the expenses. Ha ...
- 51nod1085(01背包)
题目链接: http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1085 题意: 中文题诶~ 思路: 01背包模板题. 用dp[ ...
随机推荐
- 阿里巴巴为什么主推HSF?比Dubbo有哪些优势?
作者:匿名用户链接:https://www.zhihu.com/question/39560697/answer/187538165来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请 ...
- flexible.js + makegrid.js 自适应布局
一,flexible.js 的使用方式: (一),引用方式 1,引用cdn地址 <script src="http://g.tbcdn.cn/mtb/lib-flexible/0.3. ...
- MySQL中文显示乱码
http://blog.csdn.net/acmain_chm/article/details/4174186
- 何时使用Entity或DTO
关注公众号: 锅外的大佬 每日推送国外优秀的技术翻译文章,励志帮助国内的开发者更好地成长! JPA和Hibernate允许你在JPQL和Criteria查询中使用DTO和Entity作为映射.当我在我 ...
- kubernetes调度之资源耗尽处理配置
系列目录 本篇将介绍如何使用kubelet处理资源耗尽的情况 当可用的计算机资源非常低的时候,kubelet仍然要保证节点的稳定性.当处理不可压缩的计算机资源(比如内存或磁盘空间)时,这尤其重要,当这 ...
- 阿里云 访问控制RAM
https://help.aliyun.com/product/28625.html 为用户分配最小权限 别名主要用于 RAM 用户登录以及成功登录后的显示名. 强烈建议您给主账号绑定多因素认证. 设 ...
- 第 2 章 第 2 题 找" 重数/漏数 "问题 位向量实现
问题分析 输入:一个包含了4 300 000 000个32位整数的文件( 其中可能有重复出现的数字 ) 输出:一个在这个文件中重复出现过了的数字 约束:无 解答思路 第一章中,我们学习了如何用位向量进 ...
- ASP.NET MVC EXTJS 通用主菜单框架
一.说明 首先我不知道定义的文章标题是不是准确,我这篇博文介绍的是一个通用的软件主菜单框架,界面布局用的是extjs,还是先上一个图吧. 软件主界面左侧菜单采用的风格是extjs的手风琴模式,需要注意 ...
- 2018.11.22-day24 面向对象-继承
1.归一化设计 2.抽象类 3.钻石继承 4.C3算法 5.新式类中的super
- What the 80/20 Rule Tells Us about Reducing HTTP Requests
Performance Research, Part 1: What the 80/20 Rule Tells Us about Reducing HTTP Requests https://yuib ...