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. 05_Excel操作_02_模拟Web环境的User列表导出

    [思路解释] 在正式上到WebProject之前,准备模拟一下WebProject后台的导出流程. 主要都写在ExcelService层,在Excel的Service层,首先要获得UserList,即 ...

  2. Windows下ANSI、Unicode、UTF8字符编码转换

    主意:输入字符串必须是以'\0'结尾,如果输入字符串没有以'\0'结尾,请手动设置,否则转换会有错误. unsigned int EncodeUtil::AnsiToUcs2( char* pAnsi ...

  3. C++11中新特性之:unordered_map

    unordered_map和map类似,都是存储的key-value的值,可以通过key快速索引到value. 不同的是unordered_map不会根据key的大小进行排序,存储时是根据key的ha ...

  4. MongoDB3.2版本与3.0版本写场景压力测试对比

    我们主要是为了测试journal对写操作性能的影响.分别测试了3.2版本,3.0版本在ramdisk,hdd上有journal,和没journal的情况. 发现一个很怪异的现象,3.2版本时候,随着y ...

  5. VI一个终端编辑多个文件的命令

      可分两种情况: 在不同窗口中打开多个文件:   如果已经打开一个了一个文件, 则在vi的命令输入状态下输入 :sp 另外一个文件的路径及文件名, 如此就可以在一个窗口打开多个文件了.   可以使用 ...

  6. Jquery中去除左右空格

    $.trim(" abc ");   jQuery.trim(" abc ");

  7. 降低IIScup使用率,提高性能

    智能提醒webservice在高峰期间CPU使用率达到50%,内存消耗2G优化方法:启用IIS的Web Garden. 步奏如下: 在IIS7中,选择对应的应用程序池 然后右键高级设置. 把其中的最大 ...

  8. centos下redis安装

    下载redis http://www.redis.cn/download.html 下载php的redis扩展 https://github.com/phpredis/phpredis#install ...

  9. #Leet Code# Best Time to Buy and Sell Stock

    描述:数组 A,对于 i < j, 找到最大的 A[j] - A[i] 代码: class Solution: # @param prices, a list of integer # @ret ...

  10. Servlet和Tomcat部署

    今天有空写个Servlet来玩一下.用EditPlus写一个简单的Servlet,FirstServlet.java,如下: import java.io.IOException; import ja ...