dp重拾-01背包--HDU 2602
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 ?
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.
5 10
1 2 3 4 5
5 4 3 2 1
#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的更多相关文章
- dp重拾-完全背包--HDU 4508
减肥记 湫湫给了你每日食物清单,上面描述了当天她想吃的每种食物能带给她的幸福程度,以及会增加的卡路里量. Input 输入包含多组测试用例. 每组数据以一个整数n开始,表示每天的食物清单有n种食物. ...
- DP专题·三(01背包+完全背包)
1.hdu 2126 Buy the souvenirs 题意:给出若干个纪念品的价格,求在能购买的纪念品的数目最大的情况下的购买方案. 思路:01背包+记录方案. #include<iostr ...
- POJ 2923 Relocation 装车问题 【状态压缩DP】+【01背包】
题目链接:https://vjudge.net/contest/103424#problem/I 转载于:>>>大牛博客 题目大意: 有 n 个货物,并且知道了每个货物的重量,每次用 ...
- 洛谷P1441 砝码称重 枚举 + 01背包
显然,n<=20, m<=4 的数据范围一眼爆搜. 直接搜索一下不用哪4个砝码,再做一遍01背包即可. 可能是本人太菜鸡,01背包部分调了半天QAQ-- #include<cstdi ...
- 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 ...
- P2347 砝码称重 (01背包)
题目描述 设有 1g1g1g . 2g2g2g . 3g3g3g . 5g5g5g . 10g10g10g . 20g20g20g 的砝码各若干枚(其总重 ≤1000 \le 1000≤1000 ), ...
- 0-1背包 VIOJ1025
P1025小飞侠的游园方案 请 登录 后递交 标签:[显示标签] 描述 菜虫:你的题目是--我们的情报组织探听到敌人的重要将领--小飞侠星期天会邀他的灵儿妹妹到公园去玩.公园里有很多娱乐项目,可并不是 ...
- NO11——01背包
# include <stdio.h> # include <stdlib.h> # include <string.h> # define max(x,y) x& ...
- P2871 [USACO07DEC]手链Charm Bracelet(01背包模板)
题目传送门:P2871 [USACO07DEC]手链Charm Bracelet 题目描述 Bessie has gone to the mall's jewelry store and spies ...
随机推荐
- 英文论文中i.e.,e.g.,etc.,viz.的简要小结
英文论文中i.e.,e.g.,etc.,viz.的简要小结 看了一堆用法,全白扯,自己总结的最好记,最实用 i.e. =即.换句话说.也就是说."'In essence' or 'in ot ...
- day4之函数
很快就第4天了,原来人是有惰性的,博客现在就不想写了,真是悲催,坚持,憋住. 函数 def func(name): print(name) func("huihuang") 函数定 ...
- ecshop网站搬家缓存无法更新
问题描述: 1.后台产品列表能改,数据也能看到,前端就是不显示 2.缓存无法删除 3.网上其他方法都试过,还是不行 症状:是因为缓存无法删除,无法更新,只需要能重新更新缓存文件即可.网站搬家丢失tem ...
- yourphp的sql语句
1.插入单条数据 $data[0]['cardid'] = $_POST['cardid']; $data[0]['name'] = $_POST['name']; $data[0]['mobile' ...
- Podfile升级后的影响
之前项目里用的Podfile都是版本 0.39 后面有一天电脑格盘重装以后cocoapods装的版本是 1.0.0.beta.6 那么问题来了,在下载或者clone一下项目后,经常是需要自己安装第三方 ...
- 菜鸟疑问之新建网站与新建web应用程序区别
学习asp.net一定少不了这困惑:新建网站与新建web应用程序有什么区别? 新建web应用程序 新建网站 呵呵,其实从名字看一个是webApplication,一个是webSite.名字不同罢了? ...
- 【MVC5】画面多按钮提交
画面上有个多个按钮时,如何绑定到各自的Action上? 1.追加如下MultipleButtonAttribute类 1 using System; 2 using System.Reflection ...
- java enum类
1.可以在enum中添加变量和方法 先来看一段代码示例: ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 ...
- Java Servlet系列之Servlet生命周期
Servlet生命周期定义了一个Servlet如何被加载.初始化,以及它怎样接收请求.响应请求,提供服务.在讨论Servlet生命周期之前,先让我们来看一下这几个方法: 1. init()方法 在Se ...
- adobe photoshop cc 2014 安装失败 解决办法之一
首先安装失败会有提示 首先贴下错误信息 Exit Code: 34 Please see specific errors below for troubleshooting. For example, ...