hdu1171 Big Event in HDU 01-背包
转载请注明出处:http://blog.csdn.net/u012860063
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1171
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).
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.
A is not less than B.
2
10 1
20 1
3
10 1
20 2
30 1
-1
20 10
40 40
转换为01-背包问题求解:
代码例如以下:
#include <cstdio>
#include <cstring>
#define N 200047
int f[N],val[N];
int max(int a,int b)
{
if(a > b)
return a;
else
return b;
}
int main()
{
int t,n,i,j,k,l,sum,x,y; while(scanf("%d",&n) && n>0 )
{
memset(val,0,sizeof(val));
memset(f,0,sizeof(f));
sum = 0;l = 0;
for(i = 0 ; i < n ; i++)
{
scanf("%d%d",&x,&y);
for(int p=0 ; p<y ; p++)//将价值存入数组
{
val[l++] = x;
sum+=x;
}
}
for(i = 0 ; i < l ; i++)//01背包
{
for(j = sum/2 ; j >= val[i]; j--)
{
f[j] = max(f[j],f[j-val[i]]+val[i]);
}
}
printf("%d %d\n",sum-f[sum/2],f[sum/2]);
}
return 0;
}
hdu1171 Big Event in HDU 01-背包的更多相关文章
- 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 ...
- HUD 1171 Big Event in HDU(01背包)
Big Event in HDU Problem Description Nowadays, we all know that Computer College is the biggest depa ...
- 1171 Big Event in HDU 01背包
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1171 题意:把商品分成两半,如不能均分,尽可能的让两个数相接近.输出结果:两个数字a,b且a>=b. ...
- hdu1171Big Event in HDU(01背包)
Big Event in HDU Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- HDU 1171 Big Event in HDU(01背包)
题目地址:HDU 1171 还是水题. . 普通的01背包.注意数组要开大点啊. ... 代码例如以下: #include <iostream> #include <cstdio&g ...
- Big Event in HDU(01背包)
/* 题意: 输入一个数n代表有n种物品, 接下来输入物品的价值和物品的个数: 然后将这些物品分成A B 两份,使A B的价值尽可能相等也就是尽量分的公平一些,如果无法使A B相等,那么就使A多一些: ...
- HDU 1171 Big Event in HDU(01背包)
题目链接 题意:给出n个物品的价值v,每个物品有m个,设总价值为sum,求a,b.a+b=sum,且a尽可能接近b,a>=b. 题解:01背包. #include <bits/stdc++ ...
- hdu1171 Big Event in HDU(多重背包)
http://acm.hdu.edu.cn/showproblem.php?pid=1171 多重背包题目不难,但是有些点不能漏或错. #include<iostream> #includ ...
- HDU-1171 Big Event in HDU(生成函数/背包dp)
题意 给出物品种类,物品单价,每种物品的数量,尽可能把其分成价值相等的两部分. 思路 背包的思路显然是用一半总价值当作背包容量. 生成函数则是构造形如$1+x^{w[i]}+x^{2*w[i]}+.. ...
- 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 ...
随机推荐
- Impala 源码分析-FE
By yhluo 2015年7月29日 Impala 3 Comments Impala 源代码目录结构 SQL 解析 Impala 的 SQL 解析与执行计划生成部分是由 impala-fronte ...
- Win7访问局域网内共享文件夹
\\192.168.1.102\\IP地址
- await与async的简单了解
异步方法的返回类型可以为Task.Task.void.方法不能声明ref或out参数. 无法捕捉返回类型为void的异步方法引发的异常,如果返回Task或Task的异步方法中出现异常,则在任务等待时将 ...
- Gradle 编译时选择不同的 google-services.json
在做的安卓应用需要在 debug 和 release build中使用不同的谷歌服务账号,要用到不同的google-serivces.json ,手动替换的话太费时费力,好在万能的gradle可以完成 ...
- 《第一行代码》学习笔记6-活动Activity(4)
1.SecondActivity不是主活动,故不需要配置标签里的内容. 2.Intent是Android程序中各组件之间进行交互的一种重要方式,一般可被用于 启动活动,启动服务,以及发送广播等.Int ...
- Java 访问控制符
Java提供了3个访问控制符:private.protected和public,分别代表了3个访问控制级别,另外还有一个不加任何访问控制符的访问控制级别,提供了4个访问控制级别.Java的访问控制级别 ...
- css 文本域textarea显示成label标签
<html> <head> <title>textarea显示为label</title> <style type="text/ ...
- with 与 debugger
with在严格模式下是禁止使用的,而debugger是在调试模式下才有效果的,目测作者自己在用的脚本压缩工具在有dubugger语句的情况下会影响压缩结果,导致失败. with(varible)实际上 ...
- return 与 finally
(function hello() { try { return console.log('return'); } catch (e) { } finally { console.log('final ...
- 洛谷 P1656 炸铁路
P1656 炸铁路 题目提供者kkksc03 标签图论搜索/枚举洛谷原创 难度普及/提高- 题目描述 因为某国被某红色政权残酷的高压暴力统治.美国派出将军uim,对该国进行战略性措施,以解救涂炭的生灵 ...