ACM Bone Collector
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 ?
InputThe 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.OutputOne integer per line representing the maximum of the total value (this number will be less than 2 31).Sample Input
1
5 10
1 2 3 4 5
5 4 3 2 1
Sample Output
14
#include<bits/stdc++.h>
using namespace std;
int main()
{
int dp[],n,v,nv[],nm[],t;
while(cin>>t)
{
while(t--)
{
memset(dp,,sizeof(dp)); /*初始化*/
scanf("%d %d",&n,&v); /*读取骨头数量和背包重量*/
for(int i = ; i < n; i++) /*每一个骨头的价值*/
scanf("%d",&nv[i]);
for(int i = ; i < n; i++) /*每个骨头的重量*/
scanf("%d",&nm[i]); for(int i = ; i < n; i++)
for(int j = v; j >= nm[i];j--) /*dp算法*/
dp[j] = max(dp[j],dp[j-nm[i]]+nv[i]);
cout<<dp[v]<<endl;
}
} return ;
}
参考博客:
ACM Bone Collector的更多相关文章
- hdu 2602 Bone Collector(01背包)模板
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...
- Bone Collector(01背包)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/N 题目: Description Many year ...
- HDU 3639 Bone Collector II(01背包第K优解)
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- Bone Collector II
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- HDU 2602 Bone Collector (简单01背包)
Bone Collector http://acm.hdu.edu.cn/showproblem.php?pid=2602 Problem Description Many years ago , i ...
- hdu 2602 Bone Collector 背包入门题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 题目分析:0-1背包 注意dp数组的清空, 二维转化为一维后的公式变化 /*Bone Coll ...
- hdu 2639 Bone Collector II
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 2602 Bone Collector
http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Others) ...
- Bone Collector II(HDU 2639 DP)
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
随机推荐
- SpringMVC(四):@RequestMapping结合org.springframework.web.filter.HiddenHttpMethodFilter实现REST请求
1)REST具体表现: --- /account/1 HTTP GET 获取id=1的account --- /account/1 HTTP DELETE 删除id=1的account ...
- requests-认证设置
#如果需要用户名和密码才能登陆网站,则需要认证设置auth=() import requests response = requests.get(url,auth=('user','password' ...
- U盘分区后合并
1.首先把你的U盘插在电脑上,点击开始→所有程序→附件→命令提示符(前面这步骤也可以直接用Win+R组合键打开"运行",之后输入cmd也可打开命令提示符). 2.然后在命令提示窗口 ...
- SpringMVC 自定义类型转换器
先准备一个JavaBean(Employee) 一个Handler(SpringMVCTest) 一个converters(EmployeeConverter) 要实现的输入一个字符串转换成一个emp ...
- pyqt5 动画学习(三) 指定控件的移动轨迹
这一篇来讲解自定义控件的移动轨迹 原理:我们采用QPainterPath先画一个弧线,然后加载一个物体让物体移动,设置100个关键帧,每个关键帧物体的坐标位置就是弧线的坐标位置,这样就能达到按照指定轨 ...
- 内存管理——linux内核学习
买了<深入Linux内核架构>这本书准备了解一下linux内核机制.但是最开始看了十几页感觉看着很累,本来都准备弃了 过了段时间看见一个面经有linux内核的内容,于是就照着那个先把内存管 ...
- [Codeforces]856C - Eleventh Birthday
题目大意:给出n个数,问有多少种排列把数字接起来是11的倍数.(n<=2000) 做法:一个数后面接一个数等同于乘上10的若干次幂然后加上这个数,10模11等于-1,所以10的若干次幂是-1或1 ...
- ●线段树题之wows
●模拟考试的一道似乎是学长出的题,还不错,挺考代码能力的.以此记录. ●题目以被上传(改了改说法),6128 Lence的方块们 ● (像手纸一样长的贴图……) ●题目大意: 有横向排布的n个点,每个 ...
- [Helvetic Coding Contest 2017 online mirror]
来自FallDream的博客,未经允许,请勿转载,谢谢, 第一次在cf上打acm...和同校大佬组队打 总共15题,比较鬼畜,最后勉强过了10题. AB一样的题目,不同数据范围,一起讲吧 你有一个背包 ...
- SpringCloud学习之SpringCloudBus
一.spring-cloud-bus是什么? 回答这个问题之前,我们先回顾先前的分布式配置,当配置中心发生变化后,我们需要利用spring-boot-actuator里的refresh端点进行手动刷新 ...