HDU 1171 Big Event in HDU(多重背包)
Big Event in HDU
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).
--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.
that A is not less than B.
2
10 1
20 1
3
10 1
20 2
30 1
-1
20 10
40 40
题意 把一堆东西尽量分为两份 第一份不小于第二份
把全部东西的总价值s除以2 让它装尽量多的东西作为第二份 剩下的就是第一份了
题目有个小坑点 是以负数作为结束条件的 不是-1 还有不要開始把s/=2 后来第一份又用s*2-d[s] 由于s/2*2不一定等于s了
<span style="font-family:Arial Black;">#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 55, V = 255000;
int d[V], val[N], num[N];
int main()
{
int n;
while (scanf ("%d", &n),n>0)
{
int s = 0;
memset(d,0,sizeof(d));
for (int i = 1; i <= n; ++i)
{
scanf ("%d%d", &val[i], &num[i]);
s += val[i] * num[i];
} for (int i = 1; i <= n; ++i)
{
for (int k = 1; k<=num[i]; k *=2)
{
num[i] -= k;
for (int j = s / 2; j >= k * val[i]; --j)
d[j] = max (d[j], d[j - k * val[i]] + k * val[i]);
}
if (num[i] != 0)
for (int j = s / 2; j >= num[i] * val[i]; --j)
d[j] = max (d[j], d[j - num[i] * val[i]] + num[i] * val[i]);
}
printf ("%d %d\n", s - d[s/2], d[s/2]);
}
return 0;
}
</span>
HDU 1171 Big Event in HDU(多重背包)的更多相关文章
- 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 (多重背包)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 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 多重背包
B - Big Event in HDU Nowadays, we all know that Computer College is the biggest department in HDU. B ...
- 题解报告: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(多重背包+二进制优化)
题目链接:hdu1171 思路:将多重背包转为成完全背包和01背包问题,转化为01背包是用二进制思想,即件数amount用分解成若干个件数的集合,这里面数字可以组合成任意小于等于amount的件数 比 ...
- HDU 1171 Big Event in HDU dp背包
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s ...
- 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 ...
随机推荐
- nyoj--127--星际之门(一)(生成树的数量)
星际之门(一) 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 公元3000年,子虚帝国统领着N个星系,原先它们是靠近光束飞船来进行旅行的,近来,X博士发明了星际之门,它 ...
- LeetCode.2-两个数字相加(Add Two Numbers)
这是悦乐书的第340次更新,第364篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Medium级别的第1题(顺位题号是2).给定两个非空链表,表示两个非负整数. 数字以相反的顺序存储, ...
- Irrlicht 1.8.4 + Win7 + VC2015 + x64 +OpenGL编译
1. 下载irrlicht1.8.4 https://nchc.dl.sourceforge.net/project/irrlicht/Irrlicht%20SDK/1.8/1.8.4/irrlich ...
- Scrapy中的UA池,代理池,以及selenium的应用
UA池 代理池 selenium在Scrapy中的应用 UA池 - 下载中间件: - 下载中间件(Downloader Middlewares) 位于scrapy引擎和下载器之间的一层组件. - 作用 ...
- spring-boot结合mybatis-spring的一个例子
首先spring-boot是用于简化配置的,具有可拔式组件的运用特点. 然后一下是spring-boot结合mybatis-spring的一个例子. 是一个maven项目 demo下载:http:// ...
- 如何在在页面中清除一个已知的cookie?
前些天在写一个项目的时候,使用cookie来存储一些用户数据,在用户登出时需要清理以往的数据,对于一个初学者来说,我需要学习如何清除一个已知的cookie. 首先,引入两个js文件: 1.jquery ...
- ubuntu+win10双系统,调整分区大小后进入了emergency mode
问题背景: 装了Ubuntu+win10双系统,在Ubuntu下面挂载了Windows的D盘.后来因为D空间不够,进入Windows压缩C盘分区,扩大了D盘.重启后无法启动Ubuntu,进入了emer ...
- JQuery学习笔记系列(二)----
jQuery是一个兼容多浏览器的javascript库,核心理念是write less,do more(写得更少,做得更多).其中也提供了很多函数来更加简洁的实现复杂的功能. 事件切换函数toggle ...
- SQL Server-数据库架构和对象、定义数据完整性
前言 本节我们继续SQL之旅,本节我们如题来讲讲一些基本知识以及需要注意的地方,若有不妥之处,还望指出,简短的内容,深入的理解,Always to review the basics. 数据库架构和对 ...
- Linux学习笔记(Redhat)
一.开始 linux平台上的开发 vi.gcc.gdb.make.jdk.tomcat.mysql. linux基本操作 c语言功底<c专家编程>和java语言 学习unix高级编程 &l ...