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[ ...
随机推荐
- beautifulsoup的一些使用
自动补全代码: import requests from bs4 import BeautifulSoup response=requests.get('https://www.ithome.com/ ...
- 【Hibernate步步为营】--核心对象+持久对象全析(三)
上篇文章讨论了Hibernate持久对象的生命周期,在整个生命周期中一个对象会经历三个状态,三种状态的转换过程在开发过程中是可控的.并且是通过用法来控制它们的转化过程.详细的转化过程今天就来着重讨论下 ...
- WMS8_条码界面操作简要说明(包装作业)
说明:条码界面的主要用途是包装作业 这个客户端,完全是JS实现的 可以从 All operation看板视图 Picking的表单视图 All operatio ...
- [LeetCode][Java] Best Time to Buy and Sell Stock IV
题目: Say you have an array for which the ith element is the price of a given stock on day i. Design a ...
- Jenkins Robot framework 持续集成环境搭建
为什么我们要引入RF?其实最初我们引入RF是为了能够快速的开展自动化验收测试,为敏捷保驾护航.这其中有个重要的工具Jenkins,同时也是应群里朋友们的要求,这次就来介绍一下RF如何快速便捷的结合Je ...
- Hadoop 50090端口的页面, Replication的数字是真实的文件备份数吗? (不是)
红色方框的部分,代表Hadoop系统,人工设定的文件备份数,但不是实际的备份数.文件备份数 不会大于集群机器的总数目(因为备份文件不会同时存在一台机器上,这样就没有意义),所以如果总集群数目是2,即使 ...
- ppycharm设置解释器版本号码
在pycharm中点击File,之后在弹出的窗口中输入Project Interpreter,点击之后就可以看到自己的解释器版本是多少了,也可以随意选择想要用的解释器版本号码:
- oracle ORA-06550
declare cnt integer; begin select count(0) into cnt from user_all_tables where table ...
- GuozhongCrawler系列教程 (1) 三大PageDownloader
GuozhongCrawler QQ群 202568714 教程源代码下载地址:http://pan.baidu.com/s/1pJBmerL GuozhongCrawler内置三大PageDown ...
- 九度OJ 1133:学分绩点 (加权平均数)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1333 解决:702 题目描述: 北京大学对本科生的成绩施行平均学分绩点制(GPA).既将学生的实际考分根据不同的学科的不同学分按一定的公式 ...