Bone Collector--hdu2602(01背包)
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.
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
#define N 1100
int dp[N][N];
int main()
{
int T,i,j,V,n,v[N],w[N]; scanf("%d",&T);
while(T--)
{
memset(dp,,sizeof(dp));
scanf("%d%d",&n,&V);
for(i=;i<n;i++)
scanf("%d",&v[i]);
for(i=;i<n;i++)
scanf("%d",&w[i]);
for(i=n-;i>=;i--)
{
for(j=;j<=V;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]);
}
}
printf("%d\n",dp[][V]);
}
return ;
}
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
#define N 1100
int dp[N][N];
int main()
{
int T,i,j,V,n,v[N],w[N]; scanf("%d",&T);
while(T--)
{
memset(dp,,sizeof(dp));
scanf("%d%d",&n,&V);
for(i=;i<n;i++)
scanf("%d",&v[i]);
for(i=;i<n;i++)
scanf("%d",&w[i]);
for(i=;i<n;i++)
{
for(j=;j<=V;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]);
}
}
printf("%d\n",dp[n][V]);
}
return ;
}
用一维数组;
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
#define N 1100
int dp[N];
int main()
{
int T,i,j,V,n,v[N],w[N]; scanf("%d",&T);
while(T--)
{
memset(dp,,sizeof(dp));
scanf("%d%d",&n,&V);
for(i=;i<n;i++)
scanf("%d",&v[i]);
for(i=;i<n;i++)
scanf("%d",&w[i]);
for(i=;i<n;i++)
{
for(j=V;j>=w[i];j--)
{
dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
}
}
printf("%d\n",dp[V]);
}
return ;
}
Bone Collector--hdu2602(01背包)的更多相关文章
- HDOJ(HDU).2602 Bone Collector (DP 01背包)
HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio&g ...
- HDU2602 Bone Collector(01背包)
HDU2602 Bone Collector 01背包模板题 #include<stdio.h> #include<math.h> #include<string.h&g ...
- HDU2602 Bone Collector 【01背包】
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- hdu2602 Bone Collector(01背包) 2016-05-24 15:37 57人阅读 评论(0) 收藏
Bone Collector Problem Description Many years ago , in Teddy's hometown there was a man who was call ...
- Hdu2602 Bone Collector (01背包)
Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collec ...
- hdu 2602 Bone Collector(01背包)模板
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...
- HDU 2639 Bone Collector II(01背包变形【第K大最优解】)
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- hdu 2602 - Bone Collector(01背包)解题报告
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- 题解报告:hdu 2602 Bone Collector(01背包)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Problem Description Many years ago , in Teddy’s ...
- hdu–2369 Bone Collector II(01背包变形题)
题意:求解01背包价值的第K优解. 分析: 基本思想是将每个状态都表示成有序队列,将状态转移方程中的max/min转化成有序队列的合并. 首先看01背包求最优解的状态转移方程:\[dp\left[ j ...
随机推荐
- RESTFul basic introduction
http://www.ruanyifeng.com/blog/2011/09/restful.html
- [C] 如何使用头文件 .h 编译 C 源码
在 C 语言中,头文件或包含文件通常是一个源代码文件,程序员使用编译器指令将头文件包含进其他源文件的开始(或头部),由编译器在处理另一个源文件时自动包含进来. 一个头文件一般包含类.子程序.变量和其他 ...
- DOM的学习
今天学习了DOM,感觉学习起来真的没那么简单啦,这不是一个好现象啊,只有依靠自己大补课,嘿嘿,具体的总结了一下,今天学习的其实并不多,仅仅学习了不同的节点类型,但是知识还是蛮碎的,要一点一点的总结,昨 ...
- iOS9下App Store新应用提审攻略
博文转载 CocoaChina 文/文公子 公子在第十讲中提到应用更新时需要注意的细节和苹果便捷通道的利用.今天,公子将进一步深扒iTunes Connect的面纱,为大家呈现新应用在提审前需要准备的 ...
- SALT+HASH撒盐加密
#region 撒盐加密 string salt = Guid.NewGuid().ToString(); byte[] passwordAndSaltBytes = System.Text.Enco ...
- initializer element is not constant 问题
在Ubuntu下,比葫芦画瓢,写了一个程序,居然报错!!!! #include <stdio.h> ; int j = *(int *)(&i) ; int main (int a ...
- C语言位操作--不用中间变量交换两数值
1.使用加法与减法交换两数值: #define SWAP(a, b) ((&(a) == &(b)) || \ (((a) -= (b)), ((b) += (a)), ((a) = ...
- ThreadLocal的实现和使用场景
ThreadLocal 内部实现.应用场景和内存泄漏 深入理解线程局部变量:ThreadLocal <Java源码分析>:ThreadLocal /ThreadLocalMap Threa ...
- Fiddler 教程(转载,鉴于原作者关闭了访问fiddler系列文章)
阅读目录 Fiddler的基本介绍 Fiddler的工作原理 同类的其它工具 Fiddler如何捕获Firefox的会话 Fiddler如何捕获HTTPS会话 Fiddler的基本界面 Fiddler ...
- How are you vs How are you doing
How are you与How are you doing,有何不同呢? 貌似没有不同…… 中国教科书式的回答是"Fine, thank you, and you?" 随便一点&q ...