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
 
挺久没刷DP题了,先来一个01背包预热一下
#include<iostream>
#include<cstring>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int dp[][];
int w[],v[],W,n;
int max(int a,int b)
{
if(a>=b) return a;
else return b;
}
void solve()
{
for(int i=n-;i>=;i--)
{
for(int j=;j<=W;j++)
{
if(j<w[i]) dp[i][j]=dp[i+][j];
else dp[i][j]=max(dp[i+][j],dp[i+][j-w[i]]+v[i]);
}
}
cout<<dp[][W]<<endl;
} int main()
{
int i,j,k;
scanf("%d",&k);
for(i=;i<k;i++)
{
scanf("%d %d",&n,&W);
for(j=;j<n;j++)
{
scanf("%d",&v[j]);
}
for(j=;j<n;j++)
{
scanf("%d",&w[j]);
}
solve();
W=n=;
memset(dp,,sizeof(dp));
memset(v,,sizeof(v));
memset(w,,sizeof(w));
}
return ;
}

dp重拾-01背包--HDU 2602的更多相关文章

  1. dp重拾-完全背包--HDU 4508

    减肥记 湫湫给了你每日食物清单,上面描述了当天她想吃的每种食物能带给她的幸福程度,以及会增加的卡路里量. Input 输入包含多组测试用例. 每组数据以一个整数n开始,表示每天的食物清单有n种食物. ...

  2. DP专题·三(01背包+完全背包)

    1.hdu 2126 Buy the souvenirs 题意:给出若干个纪念品的价格,求在能购买的纪念品的数目最大的情况下的购买方案. 思路:01背包+记录方案. #include<iostr ...

  3. POJ 2923 Relocation 装车问题 【状态压缩DP】+【01背包】

    题目链接:https://vjudge.net/contest/103424#problem/I 转载于:>>>大牛博客 题目大意: 有 n 个货物,并且知道了每个货物的重量,每次用 ...

  4. 洛谷P1441 砝码称重 枚举 + 01背包

    显然,n<=20, m<=4 的数据范围一眼爆搜. 直接搜索一下不用哪4个砝码,再做一遍01背包即可. 可能是本人太菜鸡,01背包部分调了半天QAQ-- #include<cstdi ...

  5. HDU 1561 The more, The Better(树形dp之树形01背包)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1561 The more, The Better Time Limit: 6000/2000 MS (J ...

  6. P2347 砝码称重 (01背包)

    题目描述 设有 1g1g1g . 2g2g2g . 3g3g3g . 5g5g5g . 10g10g10g . 20g20g20g 的砝码各若干枚(其总重 ≤1000 \le 1000≤1000 ), ...

  7. 0-1背包 VIOJ1025

    P1025小飞侠的游园方案 请 登录 后递交 标签:[显示标签] 描述 菜虫:你的题目是--我们的情报组织探听到敌人的重要将领--小飞侠星期天会邀他的灵儿妹妹到公园去玩.公园里有很多娱乐项目,可并不是 ...

  8. NO11——01背包

    # include <stdio.h> # include <stdlib.h> # include <string.h> # define max(x,y) x& ...

  9. P2871 [USACO07DEC]手链Charm Bracelet(01背包模板)

    题目传送门:P2871 [USACO07DEC]手链Charm Bracelet 题目描述 Bessie has gone to the mall's jewelry store and spies ...

随机推荐

  1. Information retrieval信息检索

    https://en.wikipedia.org/wiki/Information_retrieval 信息检索 (一种信息技术) 信息检索(Information Retrieval)是指信息按一定 ...

  2. Java——URLEncoder和URLDecoder

    import java.net.URLDecoder; import java.net.URLEncoder; //========================================== ...

  3. System类

    System类是一些与系统相关属性和方法的集合,而且System类中所有的属性都是静态的,要想引用这些属性和方法,直接使用System类调用即可. //======================== ...

  4. python开发_++i,i += 1的区分

    python开发_++i,i += 1的区分 在很多编程语言(C/C++,Java等)中我们都会碰到这样的语法: 1 int i = 0; 2 ++ i; // -- i; 这样的语法在上述编程语言中 ...

  5. 全选,全不选,反选的js实现

    全选练习       ** 使用复选框上面一个属性判断是否选中                   - checked属性                   - checked=true:选中    ...

  6. CLion注册码算法逆向分析实录

    Link is : http://www.cnblogs.com/foreach-break/p/CLion_License_Fake_Crack.html

  7. 解决DWZ(JUI)的panel 点击关闭或者打开按钮 自己写的标签消失

    问题描述:DWZ的panel面板比较常用,我们常常需要在其标题栏上再增加一个些按钮,如下图问题出来了,增加按钮后,点面板收缩按钮,增加的按钮就消失了而且面板收缩的click事件,也跟新增的按钮绑定了, ...

  8. Linux下更新时间

    方法一.使用命令 ntpdate time-a.nist.gov 方法二.本地安装ntpdate客户端 在本地安装ntpdate客户端,更新时用 ntpdate cn.pool.ntp.org 如果你 ...

  9. Java TCP 程序

    服务器采用BIO模式,每一个线程处理一个连接.问题出现在,如果使用BufferedReader去读取字符流,如果没有换行符的话,那么就会导致线程阻塞.因为调用了readLine()方法. import ...

  10. ThinkPHP整合支付宝担保交易

    ThinkPHP整合支付宝担保交易本代码参考大神 http://www.thinkphp.cn/code/240.html 的思路 1.登陆支付宝后台,下载担保交易的集成包. 2.下载完成后的文件说明 ...