Bone Collector

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 40331    Accepted Submission(s): 16756

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

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
struct node
{
int v;
int val;
}edge[1010];
int f[1010];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(f,0,sizeof(f));
memset(edge,0,sizeof(edge));
int n,v;
scanf("%d%d",&n,&v);
for(int i=0;i<n;i++)
scanf("%d",&edge[i].val);
for(int i=0;i<n;i++)
scanf("%d",&edge[i].v);
for(int i=0;i<n;i++)
{
for(int j=v;j>=edge[i].v;j--)
{
f[j]=max(f[j],f[j-edge[i].v]+edge[i].val);
}
}
printf("%d\n",f[v]);
}
return 0;
}

Bone Collector(hdoj--2602--01背包)的更多相关文章

  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 3639 Bone Collector II(01背包第K优解)

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

  3. HDU 2639 Bone Collector II【01背包 + 第K大价值】

    The title of this problem is familiar,isn't it?yeah,if you had took part in the "Rookie Cup&quo ...

  4. Bone Collector II(01背包kth)

    The title of this problem is familiar,isn't it?yeah,if you had took part in the "Rookie Cup&quo ...

  5. 杭电 2639 Bone Collector II【01背包第k优解】

    解题思路:对于01背包的状态转移方程式f[v]=max(f[v],f[v-c[i]+w[i]]);其实01背包记录了每一个装法的背包值,但是在01背包中我们通常求的是最优解, 即为取的是f[v],f[ ...

  6. hdu 2639 Bone Collector II(01背包 第K大价值)

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

  7. hdu 2639 Bone Collector II (01背包,求第k优解)

    这题和典型的01背包求最优解不同,是要求第k优解,所以,最直观的想法就是在01背包的基础上再增加一维表示第k大时的价值.具体思路见下面的参考链接,说的很详细 参考连接:http://laiba2004 ...

  8. Bone Collector II---hdu2639(01背包求第k优解)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2639求01背包的第k大解.合并两个有序序列 选取物品i,或不选.最终的结果,是我们能在O(1)的时间内 ...

  9. Bone Collector(复习01背包)

    传送门 题目大意:01背包裸题. 复习01背包: 题目 有N件物品和一个容量为V的背包.第i件物品的费用是c[i],价值是w[i].求解将哪些物品装入背包可使这些物品的费用总和不超过背包容量,且价值总 ...

  10. HDU--2639 Bone Collector II(01背包)

    题目http://acm.hdu.edu.cn/showproblem.php?pid=2639 分析:这是求第K大的01背包问题,很经典.dp[j][k]为背包里面装j容量时候的第K大的价值. 从普 ...

随机推荐

  1. Java算法——求出两个字符串的最长公共字符串

    问题:有两个字符串str1和str2,求出两个字符串中最长公共字符串. 例如:“acbbsdef”和"abbsced"的最长公共字符串是“bbs” 算法思路: 1.把两个字符串分别 ...

  2. SDOI 2018 round2游记

    Day 0 早上起来从北京到济南 住宿环境不错 不过比赛环境怎么这么low啊 而且我在最偏僻的考场中最偏僻的角落里 身边居然是个妹子?! Day1 7:40到的考试地点 发现诸位大佬已经打完板子了or ...

  3. vim的快捷键大全

    vim是开发利器,掌握快捷可以事半功倍,这里总结下常用的快捷键,提高开发速度这里写代码片 1.vim ~/.vimrc 进入配置文件 如果不知道vimrc文件在哪,可使用 :scriptnames 来 ...

  4. 【Linux】tmpfs简介及增加方式

    一. 什么是tmpfs? tmpfs是一种基于内存的文件系统,它和虚拟磁盘ramdisk比较类似,但不完全相同,和ramdisk一样,tmpfs可以使用RAM,但它也可以使用swap分区来存储.而且传 ...

  5. 微信公众号API使用总结

    官网:    https://mp.weixin.qq.com/ API:          http://mp.weixin.qq.com/wiki/home/index.html 接口调试工具:h ...

  6. C++多个文本读取问题

    同时使用两个 ifstream和 freopen 第二个就会失去效用,不知道错在了哪里! 1. 使用freopen打开: bool CPicToolsDlg::readTxt2Seq( std::st ...

  7. 新书《计算机图形学基础(OpenGL版)》PPT已发布

    为方便有些老师提前备课,1-10章所有章节已发布到本博客中. 欢迎大家下载使用,也欢迎大家给我们的新书反馈与意见,谢谢!

  8. webstorm界面主题

     http://www.webstormthemes.com/ 

  9. S-HR薪酬项目与核算表的关系

  10. 51nod1185 威佐夫游戏 V2【博弈论】

    有2堆石子.A B两个人轮流拿,A先拿.每次可以从一堆中取任意个或从2堆中取相同数量的石子,但不可不取.拿到最后1颗石子的人获胜.假设A B都非常聪明,拿石子的过程中不会出现失误.给出2堆石子的数量, ...