Bone Collector

Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)

Total Submission(s) : 65   Accepted Submission(s) : 23

Font: Times New Roman | Verdana | Georgia

Font Size: ← →

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-w[i]]+v[i]);

ac代码:


#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstring>
#define ll long long int
#define maxn 1005
using namespace std;
int v[maxn],w[maxn],dp[maxn];
int main()
{int t,n,V,i,j,ans;scanf("%d",&t);while(t--){memset(dp,0,sizeof(dp));scanf("%d %d",&n,&V);for(i=0;i<n;i++)scanf("%d",&v[i]);for(i=0;i<n;i++)scanf("%d",&w[i]);for(i=0;i<n;i++)for(j=V;j>=w[i];j--)dp[j]=max(dp[j],dp[j-w[i]]+v[i]);printf("%d\n",dp[V]);}return 0;}

hdoj2602:Bone Collector(01背包问题-dp-模版题)相关推荐

  1. HDU Bone Collector (01背包问题)

    之前背包问题学了忘学了忘= =是太笨了. 题目 许多年前,在泰迪的家乡,有一个人被称为"骨收集者".这个人喜欢收集各种骨头,例如狗,牛的骨头,他也去了坟墓-- 骨头收集者有一个大袋 ...

  2. hdu 2602 Bone Collector 01背包

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

  3. HDU 2639 Bone Collector II (dp)

    题目链接 Problem Description The title of this problem is familiar,isn't it?yeah,if you had took part in ...

  4. 01背包问题dp优化

    背包容量m给定,选择n件物品,求放入背包的最大价值. 其中,物品只能选择一次,要么放,要么不放. 朴素解法 经典的DP问题 状态:f[i][j]f[i][j]f[i][j]表示选择前iii个物品,背包 ...

  5. 动态规划---01背包问题--Dp(详解附代码)

    一.动态规划 代表一类问题(最优子结构或子问题最优性)的一般解法,是设计方法或者策略,不是具体算法 本质:递推,核心是找到状态转移的方式,写出dp方程. 解决问题:交叉,重叠子问题(最优子问题) 形式 ...

  6. 0-1背包问题(DP)-超有趣版

    0-1背包问题(DP)-超有趣版 文章目录 0-1背包问题(DP)-超有趣版 一. 0-1背包问题 二. 0-1背包问题分析 三.0-1背包问题--DP算法求解 四.0-1背包问题--DP算法深入分析 ...

  7. Bone Collector(01背包问题-两种写法)

    Many years ago , in Teddy's hometown there was a man who was called "Bone Collector". This ...

  8. HDU 2602 Bone Collector DP(01背包)

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

  9. Bone Collector(骨头收集者)c++(01背包问题)

    题目来源:杭州电子科技大学 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...

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

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

最新文章

  1. vue-router学习笔记
  2. Ubuntu中安装Eclipse的SVN插件——subclipse
  3. Vestigium-Google CodeJam 2020资格回合问题1解决方案
  4. mysql修改级联表数据_MySQL数据库 外键,级联, 修改表的操作
  5. P2216 [HAOI2007]理想的正方形
  6. Mysql授权用户数据库GRANT ON 数据库名.* TO 用户名@localhost identified BY ‘密码‘,报错ERROR 1064 (42000)
  7. 2018数学建模国赛总结(A题/编程选手视角)
  8. 基于表征(Representation)的文本匹配、信息检索、向量召回的方法总结
  9. 说说博客园的“关注”与“网摘”
  10. 蜂考数据结构c语言版答案
  11. NLP是百度的核心技术之一
  12. 十九个国内外主流的三维GIS软件(转)
  13. 斐讯路由器K2最新刷机教程
  14. pycharm txt编辑器制表符与代码中\t不匹配
  15. 这一刻我學會了堅強、給我一雙翅膀,我会向天空去翱翔。
  16. 虚拟服务器IP地址创建,虚拟服务器的ip地址
  17. spring源码学习之整合Mybatis原理分析
  18. 如何磁盘格式化?分享格式化U盘的3个方法
  19. 基于jsp的旅游信息网站的设计
  20. 关于使用dosbox与masm/MASMplus进行汇编语言的编译,link与执行中遇到问题的解决法小汇总(慢慢汇总更新)

热门文章

  1. [转]SQL Server 2000执行计划成本(2/5)
  2. python 特别慢_Python很慢?不一定哦
  3. 计算机主页为什么打不开怎么办,主页被限制,打不开怎么办?
  4. 压测服务器性能上不去,JAVA性能优化思路探究
  5. oracle 11g给表建触发器错误“索引中丢失 IN 或 OUT 参数:: 1
  6. 2019全球区块链杭州高峰论坛将于5月17日举办!
  7. nodejs导出excel
  8. 利用console.time优化js代码
  9. 爬虫之煎蛋网妹子图 大爬哦
  10. 【MySQL】Could not initialize master info structure