H - Bone Collector

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

思路如下:

这题是一个标准的01背包问题,我们需要理解01背包的状态转移方程。

题解如下

#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std; const int Len = 1005;
int dp[Len];
int v[Len],w[Len]; //v物品所占的空间,w品的价值 int main()
{
int t;
cin>>t;
while(t --)
{
int n,m;
cin>>n>>m;
for(int i = 0;i < n;i ++)
cin>>w[i];
for(int i = 0;i < n;i ++)
cin>>v[i];
memset(dp,0,sizeof(dp));
for(int i = 0;i < n;i ++)
for(int j = m;j >= v[i];j --)
dp[j] = max(dp[j],dp[j - v[i]] + w[i]); cout<<dp[m]<<endl;
}
return 0;
}

H - Bone Collector的更多相关文章

  1. HDU 2602 Bone Collector (简单01背包)

    Bone Collector http://acm.hdu.edu.cn/showproblem.php?pid=2602 Problem Description Many years ago , i ...

  2. hdu 2639 Bone Collector II

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

  3. Bone Collector(01背包+记忆化搜索)

    Bone Collector Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Tota ...

  4. HDU2602 Bone Collector 【01背包】

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

  5. HDU 2639 Bone Collector II(01背包变形【第K大最优解】)

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

  6. HDU 2602 Bone Collector(01背包裸题)

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

  7. ACM Bone Collector

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

  8. Hdoj 2602.Bone Collector 题解

    Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bone C ...

  9. hdu2602 Bone Collector 01背包

    Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like ...

随机推荐

  1. 整合Kafka+Flink 实例(第二部分 设计思路)

    前     言 拖了蛮久了,一直说要接着上一部分写设计思路以及代码,因为自己技术底子薄弱,加上人又懒,所以一直没能继续,今天补上设计思路及部分代码,后面有时间我会再补充一些应用性的功能,的确有些忙,希 ...

  2. HTC推出了VIVE Comos 全新 VR(虚拟现实)系列产品

    据 The Verge 报道,近日,HTC 推出了 VIVE Comos 全新 VR(虚拟现实)系列产品.包括 Cosmos 精英套装.VIVE Cosmos XR 版.Cosmos Play 基础版 ...

  3. Java反射之成员变量的反射

    上一篇介绍了Java反射之构造方法反射.这次我们在说一说如何反射类中的成员变量并用作一个简单案例. [一]Field类 Filed类代表字段,包含字段拥有的所有属性,比如修饰符,变量类型,值等等,Fi ...

  4. python3.4.3 连接Oracle生成报表并发送邮件

    python很简单,又很实用.当有需求时用起来会更有方向,大可不必从语法.循环等基础看起. 由于工作需要,每天要拉一份报表发给业务的同事,先是用SSIS做了个包部署到服务器上,每天定时拉报表发邮件给同 ...

  5. Spring MVC启动流程分析

    本文是Spring MVC系列博客的第一篇,后续会汇总成贴子. Spring MVC是Spring系列框架中使用频率最高的部分.不管是Spring Boot还是传统的Spring项目,只要是Web项目 ...

  6. go源码分析(三) 使用go http包开发web时遇到的坑之卸载插件,重启插件管理,仍然可以访问已经卸载的插件

    问题描述: web页面下发重启指令后,对卸载插件的处理不完整(虽然列表已经没有插件描述,但是在HandleFunc的路由列表中依然存在) 我们需要清空路由列表map 路由列表结构见代码: net/ht ...

  7. hive学习_01

    1.构建在Hadoop之上的数据仓库(数据计算使用MR,数据存储使用HDFS) 2.Hive定义了一种类SQL查询语言----HQL 3.通常用于进行离线数据处理(非实时) 4.一个ETL工具 5.可 ...

  8. Python 之 copy() 与 deepcopy() 之间的区别

    在 Python 之中,如果想要复制一个对象就免不了要理解浅复制与深复制.这也是 Python 与其他语言的区别之一. Python 的数据存储方式与其他语言不同.当你定义了一个变量: a = [, ...

  9. HTML每日学习笔记(1)

    7.15.2019 1.HTML脚本——JavaScript的嵌入使用,使 HTML 页面具有更强的动态和交互性. <script> 标签用于定义客户端脚本,比如 JavaScript. ...

  10. Spring集成axis2

    1.新建一个项目,结构如下 2.引入项目所需jar包 axis相关jar文件说明请查阅该博文 3.配置web.xml,注册axis2信息 <?xml version="1.0" ...