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 <iostream>
#include <cstring>
using namespace std;
struct node
{int val;int weight;
}a[1010];
int main()
{int t;int n,v;int i,j;cin>>t;while(t--){int dp[1005];//i表示的是重量cin>>n>>v;for(int i=0;i<n;++i)cin>>a[i].val;for(int i=0;i<n;++i)cin>>a[i].weight;memset(dp,0,sizeof(dp));for(int i=0;i<n;++i)for(int j=v;j>=a[i].weight;--j)dp[j]=max(dp[j],dp[j-a[i].weight]+a[i].val);cout<<dp[v]<<endl;}return 0;
}

hdu 2602 01背包入门相关推荐

  1. hdu 2955 01背包

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 如果认为:1-P是背包的容量,n是物品的个数,sum是所有物品的总价值,条件就是装入背包的物品的体积和不能 ...

  2. hdu 3732(01背包转多重背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3732 思路:这么大的数据,用01背包肯定会TLE的,01背包转多重背包..最多也就11*11=121件 ...

  3. 洛谷 P1048 采药 01背包入门

    P1048 采药 最近想学dp了 一道非常简单入门的01背包,写此博客做一个教训,对01背包还不是特别熟,动态方程很容易就推出来了,但是写二维状态方程时wa了,然后改为一维过了. 主要还是对01背包不 ...

  4. HDU 3466 01背包变形

    给出物品数量N和总钱数M 对于N个物品.每一个物品有其花费p[i], 特殊值q[i],价值v[i] q[i] 表示当手中剩余的钱数大于q[i]时,才干够买这个物品 首先对N个物品进行 q-p的排序,表 ...

  5. hdu 1574(01背包)

    RP问题 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Des ...

  6. HDU 2546(01背包)

    饭卡 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  7. hdu 2184 01背包变形

    转自:http://blog.csdn.net/liuqiyao_01/article/details/8753686 题意:这是又是一道01背包的变体,题目要求选出一些牛,使smartness和fu ...

  8. 01背包入门:HDU 3466 Proud Merchants

    这道题对我来说还是有点难度的,所以参考了两个博主的博客:博主1博主2 Problem Description Recently, iSea went to an ancient country. Fo ...

  9. HDU - Robberies(01背包)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2955 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

最新文章

  1. 赛森机器人_戴森扫地机器人体验:六千元的它,到底好在哪?
  2. java大会主题曲_网易未来大会主题曲发布,从创作到演唱都由AI包办
  3. same things betewen university and companies
  4. python 中 __name__ 的使用
  5. linux的定cron计划任务命令
  6. 开源社区_建立一个开源社区
  7. Python基础——@staticmethod与@classmethod
  8. 简化版shell远程登录脚本
  9. web 前端小记_1 :hasLayout
  10. 计算机房空调设计规范,空调机房防火设计规范
  11. 纪录片让你开阔眼界、增长见识
  12. Unity3D坦克大战
  13. 计算机毕业设计Android手机校园外卖订餐APP(源码+系统+mysql数据库+Lw文档)
  14. Springboot,Mybatis根据实体类自动建表
  15. DataGridview单击某个单元格选中一行
  16. SpringBoot+Vue项目校园二手交易平台
  17. 【Day3.4】东台吉尔湖
  18. 等保测评证书是由什么部门发的?申请需要满足什么条件?
  19. js对以下结构数组处理时遇到的问题(arr:[{class:“a“,team:“hero“,member:[{name:“Tom“,hobby:[“读书“,“看报“]}]}],...])
  20. ThingsBoard-警报

热门文章

  1. (八)整合spring cloud云服务架构 - commonservice-eureka 项目构建过程
  2. (11/24) css进阶:Less文件的打包和分离
  3. Nginx与Tomcat实现请求动态数据与请求静态资源的分离
  4. java替换特殊字符串
  5. 《JavaScript高效图形编程(修订版)》——6.10 用画布sprites取代DHTMLsprite
  6. mysql配置文件调优
  7. AlamofireJsonToObjects+EVReflection:一步解决JSON解析
  8. Oracle——15触发器
  9. (转) Unity3D 使用Texturepacker打包工具制作NGUI(Atlas)图集
  10. 嵌入式开发之davinci--- 8168 电源调试总结