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[1111];
int w[1111],v[1111];
int main()
{int t;while(cin>>t){while(t--){cin>>N>>V;for(int i=1;i<=N;i++){cin>>w[i];}for(int i=1;i<=N;i++){cin>>v[i];}memset(dp,0,sizeof(dp));for(int i=1;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 0;
}

posted on 2016-06-14 21:44 asuml 阅读(...) 评论(...) 编辑 收藏

转载于:https://www.cnblogs.com/asuml/p/5585570.html

HDU2602Bone Collector 简单0-1背包相关推荐

  1. HDOJ 2602-Bone Collector(0/1背包模板、打印方案及滚动数组解法)

    0/1背包 一.Bone Collector 解法一:二维数组解法(0/1背包模板代码) 1.1 0/1背包打印方案代码 解法二:滚动数组(一维)解法 2.1 一维滚动数组例题 E-爱玩游戏的Tom ...

  2. HDU2602 Bone Collector【0/1背包+DP】

    Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) T ...

  3. 动态规划(五)——0/1背包

    0/1背包 一.0/1背包问题 1.实例讲解 2.DP求解0/1背包 3.输出0/1背包方案 二.0/1背包题目代码(持续更新) 一.0/1背包问题 给定n种物品和一个背包,物品i的重量为wi,价值为 ...

  4. P1417 烹调方案 (0/1背包+贪心)

    题目背景 由于你的帮助,火星只遭受了最小的损失.但gw懒得重建家园了,就造了一艘飞船飞向遥远的earth星.不过飞船飞到一半,gw发现了一个很严重的问题:肚子饿了~ gw还是会做饭的,于是拿出了储藏的 ...

  5. 算法分析与设计——蛮力法0/1背包

    蛮力法0/1背包 蛮力法 蛮力法是一种简单直接解决问题的方法,常常直接基于问题的描述,所以蛮力法也是最容易应用的方法. 蛮力法所依赖 的基本技术是遍历,即采用一定的策略依次处理待求解问题的所有元素,从 ...

  6. 动态规划算法初步(6)——0/1 背包

    动态规划算法初步(6) 例题五:0/1 背包(背包型) 题目: 一个旅行者有一个最多能装m公斤物品的背包,现在有n件物品,它们的重量分别是w1,w2,-,wn,它们的价值分别为c1,c2,-,cn.若 ...

  7. Python 0/1背包、动态规划

    参考:http://www.cnblogs.com/fcyworld/p/6243012.html Python 0/1背包.动态规划 0/1背包问题:在能承受一定重量的背包中,放入重量不同,价值不同 ...

  8. 数据结构与算法 / 回溯算法(八皇后、0 - 1 背包)

    回溯算法,顾名思义,就是在没有得到最优解的前提下,不断的返回至前面的岔路口位置,重新选择,直至遍历了所有的情况或者得到的预期最优解的情况下再结束. 与贪心算法不同的是,回溯算法理论上是可以得到最优解, ...

  9. 简单的01背包和完全背包

    2020.12.30开始学习AcWing算法<算法竞赛进阶指南>: 上传博客方便复习. 01背包(每种物品只能使用一次): //Wecccccccc //2020.12.31 #inclu ...

最新文章

  1. uicontrol图形对象用户界面的用法
  2. 中国钢铁行业战略规划及项目建设动态分析报告2021-2027年
  3. mysql 链接慢_mysql连接非常慢的觖决办法及其它常见问题解决办法
  4. DM6467T开发板领航——dmai经验谈
  5. GitHub 标星 11000+,阿里开源微服务如何连续 10 年扛住双十一大促
  6. 【C++】 Boost 库编译技巧总结
  7. 使用JAVA来获得本日,本周,本月,本年的时间信息
  8. Javascript 细节散记
  9. 修改alert提示框的css样式
  10. MMC-HVDC仿真模型,pscad柔性直流输电仿真mmc仿真模型,双端mmc模型,MMC为21电平NLM和均压控制
  11. 3D打印:我的打印机使用经验技巧记录
  12. 开源中国众包平台派活:微信小程序任务
  13. 自动注册gmail邮箱构想
  14. uva-10041-水题
  15. 华为机试——字符串压缩(stringZip)
  16. 安卓仿Toasty消息弹框
  17. RIP路由项欺骗攻击实验
  18. leetcode-167-两数之和 II
  19. 简单三步!教你用前端表格控件SpreadJS做购物车
  20. 【goldengate】官方文档笔记三 Oracle GoldenGate 实时报表

热门文章

  1. markdown 转义字符
  2. 2017 ICPC西安区域赛 A - XOR ,线段树合并线性基
  3. django cookie、session
  4. ubuntu16.04 安装caffe以及python接口
  5. Angular1.63 绑定数据与继承
  6. cocos2d-x 2.2 创建项目
  7. OpenCV人脸检测并把图片写成avi视频
  8. 二叉树学习笔记--先序遍历
  9. java程序转成mac应用,如何为Java应用程序创建Mac安装程序?
  10. 计算机的双一流学校,分数不够上双一流大学计算机专业,上这些大学也不错,实力非常强...