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 ...
随机推荐
- Android+Jquery Mobile学习系列-目录
最近在研究学习基于Android的移动应用开发,准备给家里人做一个应用程序用用.向公司手机移动团队咨询了下,觉得使用Android的WebView上手最快,因为WebView等于是一个内置浏览器,可以 ...
- 【BZOJ2438】【中山市选2011】杀人游戏
[问题描述] 一位冷血的杀手潜入 Na-wiat,并假装成平民.警察希望能在 N 个人里面, 查出谁是杀手. 警察能够对每一个人进行查证,假如查证的对象是平民,他会告诉警察,他认识的人, 谁是杀手, ...
- C Linux read write function extension
前言 - 赠送 readn / writen Linux 上默认的 read 和 write 函数会被信号软中断. 且 read 和 write 函数中第三个参数 count #include < ...
- HDU 2520 我是菜鸟我怕谁
2019-05-27 17:52:01 加油!!! 看题时候就要仔细,最后容易忘记%10000 #include <bits/stdc++.h> using namespace std; ...
- ES6 Proxy 性能之我见
ES6 Proxy 性能之我见 本文翻译自https://thecodebarbarian.com/thoughts-on-es6-proxies-performance Proxy是ES6的一个强力 ...
- springboot的推荐模板引擎-Thymeleaf
1)添加对themeleaf的支持的依赖 <!--Thymeleaf--> <dependency> <groupId>org.springframework.bo ...
- 软件需求规范说明 (Software Requirements Specification, 简称SRS)
GB/T 9385-2008 笔记 为了形成确定和完备的规格说明, 我们需要明确 软件的顾客希望得到什么; 软件的供方理解用户想要什么; 4.2 SRS的基本性质 SRS是对在具体环境中执行确定功能的 ...
- 豆瓣项目(用react+webpack)
用豆瓣电影api的项目 电影列表组件渲染 步骤: 1. 发送Ajax请求 1.1 在组件的componentWillMount这个生命周期钩子中发送请求 1.2 发送ajax XMLHttpReque ...
- Static variables in JavaScript
function MyClass () { // constructor function var privateVariable = "foo"; //NO:obj.privat ...
- Python Tutorial笔记
Python Tutorial笔记 Python入门指南 中文版及官方英文链接: Python入门指南 (3.5.2) http://www.pythondoc.com/pythontutorial3 ...