Bone Collector

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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 2 31).

Sample Input

1
5 10
1 2 3 4 5
5 4 3 2 1

Sample Output

14

很基础的一道dp熟悉一下
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iomanip>
#include <math.h>
#include <map>
using namespace std;
#define FIN     freopen("input.txt","r",stdin);
#define FOUT    freopen("output.txt","w",stdout);
#define INF     0x3f3f3f3f
#define lson    l,m,rt<<1
#define rson    m+1,r,rt<<1|1
typedef long long LL;const int MAXN=1005;
int dp[MAXN][MAXN];
int value[MAXN];
int volume[MAXN];int main()
{//FINint T;scanf("%d",&T);while(T--){int n,v;scanf("%d%d",&n,&v);for(int i=1;i<=n;i++)scanf("%d",&value[i]);for(int i=1;i<=n;i++)scanf("%d",&volume[i]);memset(dp,0,sizeof(dp));for(int i=1;i<=n;i++)for(int j=0;j<=v;j++){if(j>=volume[i])dp[i][j]=max(dp[i-1][j],dp[i-1][j-volume[i]]+value[i]);elsedp[i][j]=dp[i-1][j];}printf("%d\n",dp[n][v]);}}

  

转载于:https://www.cnblogs.com/Hyouka/p/5730984.html

HDU 2602 Bone Collector DP(01背包)相关推荐

  1. hdu 2602 Bone Collector(01背包)模板

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...

  2. hdu 2602 Bone Collector(01背包)

    题意:给出包裹的大小v,然后给出n块骨头的价值value和体积volume,求出一路下来包裹可以携带骨头最大价值 思路:01背包 1.二维数组(不常用 #include<iostream> ...

  3. HD 2602 Bone Collector (0-1背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Problem Description Many years ago , in Teddy's ...

  4. hdu 2602 Bone Collector 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 在没学01背包时做的,很遗憾的是,wa了很多次. wa代码 1 #include <ios ...

  5. hdu 2602 Bone Collector 01背包

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

  6. HDU Problem 2062 Bone Collector【01背包】

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

  7. Bone Collector【01背包】

    F - Bone Collector HDU - 2602 Many years ago , in Teddy's hometown there was a man who was called &q ...

  8. hdu 2602 Bone Collector

    终于开始做自己一直不敢碰的dp了,内心颇不平静.很久以前看过的背包九讲也没什么印象了.这个题错了四次.之前老师有说过看到dp不要把它想成dp,要按照数学归纳的路子来.先来个最初的归纳假设,如果过弱再加 ...

  9. HDU 2602 Bone Collector - from lanshui_Yang

           题目大意:有n件物品,每件物品均有各自的价值和体积,给你一个容量为 V 的背包,问这个背包最多能装的物品的价值是多少?        解题思路:这是一道0 - 1 背包的简单模板题,也是 ...

最新文章

  1. 利用ListView实现新闻客户端的新闻内容图文混排
  2. Hadoop HDFS概念学习系列之熟练掌握HDFS的Shell访问(十五)
  3. HEX、DEC、OCT和BIN的解释
  4. PHP的display_errors与error_reporting
  5. android 6关闭防火墙,安卓手机如何关闭防火墙
  6. opencv2.4.9报错找不到opencv_video249d.dll
  7. linux c设置系统时间函数,Linux C 中获取local日期和时间 time()localtime()函数
  8. 简述中断处理的6个步骤_基于SCDM软件的CFD前处理工作5个步骤
  9. lj245a引脚功能图_CA3140中文资料-引脚图及功能
  10. 以编程方式使用 Microsoft Office Visio 2003 ActiveX 控件
  11. Could Not find resource [logback.groovy] ; Cound Not find resource [logback-test.xml]
  12. 微信小程序授权微信开放平台
  13. 如何退出或卸载奇安信天擎软件
  14. 坚持住啊,还在代码屎山中爬行的同事们
  15. go mod invalid pseudo-version
  16. 「Computer keyboard」- 在键盘中,手指的摆放位置 @20210331
  17. Win10 无法使用内置管理员账户打开应用程序解决方案
  18. 一文了解无聊猿(BAYC)的 NFT 帝国是如何形成的
  19. L2-3 清点代码库 (25 分)
  20. 请问这个动态表格的表单内容如何写才能存入ACCess数据库中

热门文章

  1. 百度大脑发挥AI“头雁效应” 王海峰:在AI时代共同推动社会智能化升级
  2. 干货丨人工智能、机器学习和认知计算入门指南
  3. 如何使用gensim来加载和使用词向量模型word2vec
  4. 显式欧拉法求解常微分方程
  5. 马斯克:今年占全球发射质量65%,星舰5月或首次轨道试飞
  6. 喻国明:“元宇宙”背后的未来图景
  7. Science长文综述:通过空间斑图形成避免复杂系统崩溃
  8. 从人类交互通信发展简史看元宇宙发展趋势及商业价值
  9. 学科交叉是科学发展的必然趋势
  10. 交叉科学部如何建?基金委:要做好这4点