hdu2602 Bone Collector 01背包
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.
#include <bits/stdc++.h> using namespace std;
int t,n,m,v[],w[],i,j,f[][];
int main()
{
cin>>t;
while(t--){
cin>>n>>m;
for(i=;i<=n;i++) cin>>v[i];
for(i=;i<=n;i++) cin>>w[i];
memset(f,,sizeof(f));
for(i=;i<=n;i++) //装入第i个骨头时,背包容量为j时的最大价值
for(j=;j<=m;j++){
if(j<w[i]){
f[i][j]=f[i-][j];
}
else{
f[i][j]=max(f[i-][j],f[i-][j-w[i]]+v[i]);
}
}
cout<<f[n][m]<<endl;
}
return ;
}
#include <bits/stdc++.h> using namespace std;
int n,m,f[],v[],w[],i,j,t; int main()
{
cin>>t;
while(t--){
cin>>n>>m;
for(i=;i<=n;i++) cin>>v[i];
for(i=;i<=n;i++) cin>>w[i];
memset(f,,sizeof(f));
for(i=;i<=n;i++)
for(j=m;j>=w[i];j--){
if(f[j]<f[j-w[i]]+v[i])
f[j]=f[j-w[i]]+v[i];
}
cout<<f[m]<<endl;
}
return ;
}
hdu2602 Bone Collector 01背包的更多相关文章
- [原]hdu2602 Bone Collector (01背包)
本文出自:http://blog.csdn.net/svitter 题意:典型到不能再典型的01背包.给了我一遍AC的快感. //=================================== ...
- hdu2602 Bone Collector (01背包)
本文来源于:http://blog.csdn.net/svitter 题意:典型到不能再典型的01背包.给了我一遍AC的快感. //================================== ...
- 解题报告:hdu2602 Bone collector 01背包模板
2017-09-03 15:42:20 writer:pprp 01背包裸题,直接用一维阵列的做法就可以了 /* @theme: 01 背包问题 - 一维阵列 hdu 2602 @writer:ppr ...
- HDU-2602 Bone Collector——01背包
首先输入一个数字代表有n个样例 接下来的三行 第一行输入n 和 v,代表n块骨头,背包体积容量为v. 第二行输入n块骨头的价值 第三行输入n块骨头的体积 问可获得最大的价值为多少 核心:关键在于d ...
- Bone Collector(01背包+记忆化搜索)
Bone Collector Time Limit : 2000/1000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tota ...
- 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 Many years ago , in Teddy’s hometown there was a ...
- HDU 2602 Bone Collector --01背包
这种01背包的裸题,本来是不想写解题报告的.但是鉴于还没写过背包的解题报告.于是来一发. 这个真的是裸的01背包. 代码: #include <iostream> #include < ...
- ACM HDU Bone Collector 01背包
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 这是做的第一道01背包的题目.题目的大意是有n个物品,体积为v的背包.不断的放入物品,当然物品有 ...
随机推荐
- c# c/s 框架读取的配置文件时是app.exe.config
c# c/s 框架读取的配置文件时是app.exe.config, 一般在bin中间中俄debug中或者Release中
- bootstrap table 冻结列 ie 兼容
修改前: Chrome效果 Ie11效果 修改后: Ie11效果 修改bootstrap-table-fixed-columns.js文件 修改其中的initBody方法 修改为
- EcustOJ P109跳一跳(离散化+dp)
题目链接 感觉这道题我看了很多天,胡思乱想啊,一开始觉得记忆化搜索会可能T啊,,可能出题人的数据卡的好就稳T了的感觉..后来想了想,好像离散化一下,记一下位置之后再记忆化搜索就应该稳了吧..(好像直接 ...
- xenserver 上传centos6.8镜像
1.宿主机操作: # mkdir /iso # xe sr-create name-label=system-iso type=iso device-config:location=/iso de ...
- node里面的buffer理解
node提供了专门读写文件的模块,文件内容都是2进制存放在内存中的 node读取文件的结果都是16进制,那么你要学会进制转换,二进制0b开头 ,八进制0开头,十六进制0x 基础知识: 1字节=8bit ...
- Eclipse 自动生成 Ant的Build.xml 配置文件
Eclipse 自动生成 Ant的Build.xml 配置文件,生成的方法很隐蔽 选择你要生成Build.xml文件的项目,右键. Export-> General -> Ant Buil ...
- Unicode与Ansi互转
BOOL CTool::AnsiToUnicode(const char *pSrc, CString &strResult) { #ifndef _UNICODE return FALSE; ...
- day 12 - 1 装饰器进阶
装饰器进阶 装饰器的简单回顾 装饰器开发原则:开放封闭原则装饰器的作用:在不改变原函数的调用方式的情况下,在函数的前后添加功能装饰器的本质:闭包函数 装饰器的模式 def wrapper(func): ...
- 为何invalidate()不可以直接在UI线程中调用&invalidate与postInvalidate
1.android ui操作为什么一定要在主线程中执行? 答:Android UI操作是单线程模型,关于UI更新的相关API(包括invalidate())都是按照单线程设计的,对于多线程运行时不安全 ...
- MySql cmd下的学习笔记 —— 有关修饰器的知识(trigger)
关于触发器的理解: 进行数据库应用软件的开发时,有时我们碰到表的某些数据的改变时,希望同时 引起其他相关数据改变的需求,利用触发器就能满足这样的需求. 触发器能在表中的某些特定数据变化时自动完成某些查 ...