http://acm.hdu.edu.cn/showproblem.php?pid=2602

Bone Collector

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 32408    Accepted Submission(s): 13329

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

 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int v[],w[];
int n,c;
int f[][];//对于dp(i,j)就表示可选物品为i…n背包容量为j(总重量)时背包中所放物品的最大价值。
void backpack()
{
int i,j;
for(i=;i<=n;i++)
for(j=;j<=c;j++)
{
if(i==)
f[i][j]=;
else
f[i][j]=f[i-][j];
if(j>=v[i])
f[i][j]=max(f[i][j],f[i-][j-v[i]]+w[i]);
}
printf("%d\n",f[n][c]);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int i;
scanf("%d%d",&n,&c);
for(i=;i<=n;i++)
scanf("%d",&w[i]);
for(i=;i<=n;i++)
scanf("%d",&v[i]);
backpack();
}
return ;
}

HDU 2602 Bone Collector的更多相关文章

  1. HDU 2602 Bone Collector 0/1背包

    题目链接:pid=2602">HDU 2602 Bone Collector Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...

  2. HDOJ(HDU).2602 Bone Collector (DP 01背包)

    HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...

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

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

  4. HDU 2602 Bone Collector(经典01背包问题)

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

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

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

  6. hdu 2602 Bone Collector 背包入门题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 题目分析:0-1背包  注意dp数组的清空, 二维转化为一维后的公式变化 /*Bone Coll ...

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

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

  8. HDU 2602 - Bone Collector - [01背包模板题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Many years ago , in Teddy’s hometown there was a ...

  9. 题解报告:hdu 2602 Bone Collector(01背包)

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

随机推荐

  1. IOS-开发日志-UIScrollView

    UIScrollView 1.  contentOffset 默认CGPointZero,用来设置scrollView的滚动偏移量. // 设置scrollView的滚动偏移量 scrollView. ...

  2. O-C相关-07-@property关键字简介与使用

    基本概念:在O-C中,创建完类之后还需要给一个类添加属性和方法,之前说过的set和get方法比较繁琐,因此引入了@property 这个编译器指令.@property 是一个编译器指令.所谓的编译器指 ...

  3. java面试入门总结

    最近正好有时间空下来,前一段时间本来打算呢,写一写阶段的总结,今天就来谈谈吧.作为一个java入门小白,之前就职于浙江大华,是通过大华10月份秋季招聘通过大华的面试. 浙江大华校招采用模式是先笔试.再 ...

  4. javaee学习-servlet初始化参数

    1.需要定义ServletConfig对象来接收servlet配置的初始化参数. 2.当servlet配置了初始化参数后,web容器在创建servlet实例对象时, 会自动将这些初始化参数封装到Ser ...

  5. Batch file Functions

    Quote from: http://ss64.com/nt/syntax-functions.html Batch file Functions Packaging up code into a d ...

  6. nginx 代理 proxy_pass设置

    #img.test.com/img1 实际访问的路径是 http://127.0.0.1:123/a1 #img.test.com/img2 实际访问的路径是 http://127.0.0.1:123 ...

  7. gcc 生成动态库时-fpic选项是什么意思。

    -f后面跟一些编译选项,PIC是其中一种,表示生成位置无关代码(Position Independent Code)

  8. WinForm聊天室

    前几天开始学Socket编程,跟着老师一点一点的做.最后做了一个WinForm版的小聊天室.这个聊天室的客户端和服务端都只是在本机上运行. 这里我首先和大家谈谈我对聊天室的一点理解,聊天室其实是服务端 ...

  9. python类库26[web2py之基本概念]

    一 web2py的应用的执行环境Models,Controllers和views所在的执行环境中,以下对象已经被默认地导入: Global Objects:  request,response,ses ...

  10. gcc向待编译源文件传入参数的方法

    gcc有两种方法向待编译源文件传入参数 第一种 利用–Dmacro=name 编译选项,详见gcc -D选项 第二种 利用链接脚本(*.lds)传入参数,类似于ADS的编译器参数可以被待编译源文件调用 ...