HDU2602Bone Collector 简单0-1背包
Bone Collector
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 48618 Accepted Submission(s): 20269
Problem Description
Many years ago , in Teddy’s hometown there was a man who
was called “Bone Collector”. This man like to collect varies of bones , such as
dog’s , cow’s , also he went to the grave …
The bone collector had a big bag with a volume of V ,and along his trip of collecting
there are a lot of bones , obviously , different bone has different value and
different volume, now given the each bone’s value along his trip , can you
calculate out the maximum of the total value the bone collector can get ?
Input
The first line contain a integer T , the number of cases.
Followed by T cases , each case three lines , the first line contain two
integer N , V, (N <= 1000 , V <= 1000 )representing the number of bones
and the volume of his bag. And the second line contain N integers representing
the value of each bone. The third line contain N integers representing the
volume of each bone.
Output
One integer per line representing the maximum of the
total value (this number will be less than 231).
Sample Input
1
5 10
1 2 3 4 5
5 4 3 2 1
Sample Output
14
注意:先输入每个骨头的价值然后输入每个骨头的体积。
状态转移方程:dp[j]=max(dp[j],dp[j-v[i]]+w[i]。
#include <iostream>
#include <string.h> using namespace std;
int N,V;
int dp[];
int w[],v[];
int main()
{
int t;
while(cin>>t){
while(t--){
cin>>N>>V;
for(int i=;i<=N;i++){
cin>>w[i];
}
for(int i=;i<=N;i++){
cin>>v[i];
}
memset(dp,,sizeof(dp));
for(int i=;i<=N;i++){
for(int j=V;j>=v[i];j--){ //j如果小于了v[i]那么v[i]一定无法装入袋子
dp[j]=max(dp[j],dp[j-v[i]]+w[i]);
}
}
cout<<dp[V]<<endl;
}
}
return ;
}
HDU2602Bone Collector 简单0-1背包的更多相关文章
- HDU1712简单的分组背包
HDU1712http://acm.hdu.edu.cn/showproblem.php?pid=1712 简单的分组背包 #include <map> #include <set& ...
- P1417 烹调方案 (0/1背包+贪心)
题目背景 由于你的帮助,火星只遭受了最小的损失.但gw懒得重建家园了,就造了一艘飞船飞向遥远的earth星.不过飞船飞到一半,gw发现了一个很严重的问题:肚子饿了~ gw还是会做饭的,于是拿出了储藏的 ...
- poj1417 带权并查集+0/1背包
题意:有一个岛上住着一些神和魔,并且已知神和魔的数量,现在已知神总是说真话,魔总是说假话,有 n 个询问,问某个神或魔(身份未知),问题是问某个是神还是魔,根据他们的回答,问是否能够确定哪些是神哪些是 ...
- 洛谷 P1064 金明的预算方案 (有依赖的0/1背包)
题目描述 金明今天很开心,家里购置的新房就要领钥匙了,新房里有一间金明自己专用的很宽敞的房间.更让他高兴的是,妈妈昨天对他说:“你的房间需要购买哪些物品,怎么布置,你说了算,只要不超过NN元钱就行”. ...
- POJ 1636 Prison rearrangement DFS+0/1背包
题目链接: id=1636">POJ 1636 Prison rearrangement Prison rearrangement Time Limit: 3000MS Memor ...
- POJ 1745 【0/1 背包】
题目链接:http://poj.org/problem?id=1745 Divisibility Time Limit: 1000MS Memory Limit: 10000K Total Sub ...
- 浙大PAT CCCC L3-001 凑零钱 ( 0/1背包 && 路径记录 )
题目链接 分析 : 就是一个 0/1 背包,但是需要记录具体状态的转移情况 这个可以想象成一个状态转移图,然后实际就是记录路径 将状态看成点然后转移看成边,最后输出字典序最小的路径 这里有一个很巧妙的 ...
- 牛客网 TaoTao要吃鸡 ( 0/1背包变形 )
题意 : 题目链接 分析 : 如果没有 BUG (即 h == 0 的时候)就是一个普通的 0 / 1 背包 需要讨论一下 h != 0 的情况 此时有就相当于有物品是有特权的 而且背包装有特权的物 ...
- HDU 2602 Bone Collector 0/1背包
题目链接:pid=2602">HDU 2602 Bone Collector Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...
随机推荐
- List<实体>与List<String>数据互转
1.List<实体>数据: public List<Device> queryOSDevice(String cpu,String ip,String name){ Strin ...
- Solr6.6.0 用 SimplePostTool索引文件 中文乱码
在用SimplePostTool工具导入CSV文件,文件内容如下: 启动solr ,利用命令导入:java -Dtype=text/csv -Dc=solr_test -jar post.jar .. ...
- cakephp事务处理
使用cakephp框架做开发时,涉及到多个数据表的数据保存,需要使用cakephp的事务处理,查cakephp的说明手册也没看明白,从开发社区中看到了解决的办法,考虑到英文的问题,所以转给大家,以供参 ...
- linux 输出重定向 何时会写文件
linux 输出重定向 何时会写文件 测试到了8K才会进行flush:
- 小程序image的13种mode
注:image组件默认宽度300px.高度225px mode 有效值: mode 有 13 种模式,其中 4 种是缩放模式,9 种是裁剪模式. 缩放: 裁剪: 文章来 ...
- 绘制 SVG
工具网址:http://svg123.com/ 画布 点击画布,在页面的右侧我们可以调整画布属性 点击属性,滚动滑轮可以微调 或者直接双击修改属性值 工具栏 左侧工具栏 就像画图的工具栏一样 形状库 ...
- 【Excle】动态更新数据下拉菜单
现在我们制作了一个简单的下拉菜单,如下: 但是随着公司的逐渐扩大,部门也变得多了,目前我是把数据范围写死的 ,所有每次添加一个部门,就得修改数据范围,那么现在我们不想修改这个范围了,想让他每次添加部门 ...
- javascript 清空数组的方法
1,splice var ary = [1,2,3,4]; ary.splice(0,ary.length); console.log(ary); // 输出 [],空数组,即被清空了 2,lengt ...
- 监控应用服务器使用JMX监控Tomcat (推荐)
前言:做了一个监控应用服务器的项目(支持Tocmat.WebSphere.WebLogic各版本), 过程也算是磕磕绊绊,由于网上缺少相关资料,或者深陷于知识的海洋难以寻觅到有效的资料,因而走过不少弯 ...
- logstash5 单实例多配置文件实现
有些服务器上有多个服务,要使用单个logstash收集日志,因为有多个配置文件,刚开始使用 /opt/app/logstash/bin/logstash "--path.settings&q ...