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. re正则表达式6_+

    + means"match one or more" the group proceding a plus must appear at least once. # -*- cod ...

  2. ajax返回数据类型为XML数据的处理

    /*XML:可扩展标记语言 HTML:超文本标记语言 标签:<标签名></标签名> 特点: 1.必须要有一个根 2.标签名自定义 3.对大小写敏感 4.有开始就要有结束 5.同 ...

  3. TCP/IP详解

    第一篇 TCPIP协议详解 第1章 TCPIP协议族 第2章 IP协议详解 第3章 TCP协议详解 第4章 TCP/IP通信案例:访问Internet上的Web服务器 一.TCP/IP协议族 TCP/ ...

  4. ecshop登录

    邮箱登录 a.找到function login(){} ,增加一个邮箱判断is_mail()  , b.如果通过,增读取出username , c.再通过默认的login功能 1.需要修改文件incl ...

  5. -[UIWindow viewForFirstBaselineLayout]: unrecognized selector sent to instance

    #ifdef DEBUG #import <UIKit/UIKit.h> #import <objc/runtime.h> @implementation UIView (Fi ...

  6. 第一次使用Android Studio时你应该知道的一切配置

    ​[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/ ...

  7. webapi输入验证过滤器ValidationActionFilter

    public class validationActionFilter:ActionFilterAttribute { public override void OnActionExecuting(S ...

  8. Entity Framework - Using Transactions or SaveChanges(false) and AcceptAllChanges()?

    LINK With the Entity Framework most of the time SaveChanges() is sufficient. This creates a transact ...

  9. Orchard源码分析(4.3):Orchard.Events.EventsModule类(Event Bus)

    概述 采用Event Bus模式(事件总线),可以使观察者模式中的观察者和被观察者实现解耦. 在.Net 中使用观察者模式,可以使用事件(委托)和接口(类).Orchard Event  Bus使用的 ...

  10. mysql 用sql 语句去掉某个字段重复值数据的方法

    示例代码如下: create table tmp as select min(主键) as col1 from 去重表名 GROUP BY 去重字段; delete from 去重表名 where 主 ...