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. Simulink仿真入门到精通(三) Simulink信号

    3.1 Simulink信号概述 所谓信号,表示一种随着时间而变化的量,在时间轴上的采样时刻都对应有数值. 信号在Simulink中是相当重要的组成部分,有线(line)表示,在模型中穿针引线地将各模 ...

  2. JavaScript 预编译与作用域

    JavaScript 预编译与作用域 JavaScript 预编译的过程和作用域的分析步骤是 JS 学习中重要的一环,能够帮助我们知道代码的执行顺序,更好理解闭包的概念 预编译 JavaScript ...

  3. php 数据库 操作

    header.php <?php error_reporting(0);//加上error_reporting(0);就不会弹出警告了 // header("Content-type: ...

  4. java基本类型、数组、和枚举类型

    开始之前先吐槽一下,学艺不精,面试要吃大亏,出来混迟早要还的. 别的不说了,从零开始复习基础知识 1.标识符和关键字 意义:标识符用于对变量.类.和方法的命名.规范的标识符命名可以提高程序的可读取性. ...

  5. 聊聊OkHttp实现WebSocket细节,包括鉴权和长连接保活及其原理!

    一.序 OkHttp 应该算是 Android 中使用最广泛的网络库了,我们通常会利用它来实现 HTTP 请求,但是实际上它还可以支持 WebSocket,并且使用起来还非常的便捷. 那本文就来聊聊, ...

  6. 44. 更改oracle字符集编码american_america.zh16gbk 改为 SIMPLIFIED CHINESE_CHINA.ZHS16GBK

    注册表NLS_LANG值改为SIMPLIFIED CHINESE_CHINA.ZHS16GBK

  7. Caused by: java.lang.IllegalArgumentException

    Caused by: java.lang.IllegalArgumentException 是因为jdk较高而项目需要的是低版本的问题 1.将idea或idea里的语言级别调到适合自己项目的版本比如安 ...

  8. 玩转控件:封装Dev的LabelControl和TextEdit

    俗话说的好:"工欲善其事必先利其器",作为软件攻城狮也是同样道理,攻城狮开发的软件目的是简化客户的操作,让客户动动手指就可以完成很多事情,减少人力成本.这也是系统/软件存在的目的. ...

  9. VMWARE虚拟机安装系统提示CPU已被客户机操作系统禁用和secureCUT乱码

    错误:VMWARE虚拟机安装系统提示CPU已被客户机操作系统禁用 改正:找到虚拟机的位置找到下图灰色的部分:打开 .vmx后缀的操作系统配置文件,加入以下代码: cpuid.1.eax = :: 2. ...

  10. VsCode编辑器那些事

    1.怎么改成中文的? 按快捷键“Ctrl+Shift+P” 在框下点击“configur Display language" 会跳转至商店,选择插件下载“Chinese (Simplifie ...