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 ...
随机推荐
- css让图片作为按钮的背景并且大小合适
最近在做ASP大作业,在做html页面的时候想把一个图片作为按钮的背景,搞了好久终于在csdn上找到了满意的答案: background-size: cover; 只需要这一句就ok了,就是这么简答. ...
- Linux下的网络环境配置
- Behavior Trees
https://en.wikipedia.org/wiki/Behavior_Trees_(artificial_intelligence,_robotics_and_control) http:// ...
- VS2013快捷键大全
Ctrl+E,D ----格式化全部代码 Ctrl+E,F ----格式化选中的代码 CTRL + SHIFT + B生成解决方案 CTRL + F7 生成编译 CTRL + O 打开文件 CTRL ...
- DELL服务器引导光盘图片及下载链接
DELL服务器引导光盘图片及下载链接 所有的下载地址均是ftp开头的,下载时,请 拷贝下载地址,然后放到浏览器的地址栏进行下载! 各个下载地址汇总: http://search.dell.com/re ...
- Spring实战 (第3版)——依赖注入
首先弄明白几个概念: 1.什么是POJO 2.JavaBean规范 3.EJB(Enterprise JavaBean) 体会Spring如何简化Java开发. 创建应用对象(组件)之间协作关系的行为 ...
- linux下如何查看chm文件
转自:http://www.cnblogs.com/jesseZh/p/4036811.html (64位) sudo dpkg -i chmsee_1.3.0-2ubuntu2_amd64.d ...
- c#winform选择文件,文件夹,打开指定目录方法
private void btnFile_Click(object sender, EventArgs e) { OpenFileDialog fileDialog = new OpenFileDia ...
- "当前方法的代码已经过优化,无法计算表达式的值"的这个错误的解决方案!!!
http://blog.useasp.net/archive/2012/09/12/how-to-debug-dotnet-framework-source-when-throw-the-code-o ...
- python SMTP邮件发送(转载)
Python SMTP发送邮件 SMTP(Simple Mail Transfer Protocol)即简单邮件传输协议,它是一组用于由源地址到目的地址传送邮件的规则,由它来控制信件的中转方式. py ...