博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU2602——Bone Collector
阅读量:4992 次
发布时间:2019-06-12

本文共 1876 字,大约阅读时间需要 6 分钟。

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 9023    Accepted Submission(s): 3467

Problem Description
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 ?
 

 

Input
The 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.
 

 

Output
One 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
 
 
 
 
 
基本的01背包问题,状态方程
f[v]=max{f[v],f[v-c[i]]}
 
代码:
View Code
#include 
#include
#define N 1001 struct _bone {
int value; int volume; }bone[N]; int f[N]; int max(int a, int b) {
return a > b ? a : b; } int main() {
int t, n, v; int i, j, k; scanf("%d", &t); for(k=0;k
=0;j--) {
if(j >= bone[i].volume) {
f[j] = max(f[j], f[j-bone[i].volume]+bone[i].value); } } } printf("%d\n", f[v]); } return 0; }

转载于:https://www.cnblogs.com/sdutacmer/archive/2011/12/08/2280790.html

你可能感兴趣的文章
2. 组建的注册与引入
查看>>
Excel 相关实用计算公式
查看>>
1169.比较奇偶数个数
查看>>
Java – How to convert Array to Stream
查看>>
java学习1-环境搭建
查看>>
c# 获取当前季的第一天以及最后一天
查看>>
MYSQL生成两个日期之间的所有日期数据
查看>>
shell脚本安装jdk
查看>>
( 转)Sqlserver中tinyint, smallint, int, bigint的区别 及 10进制转换16进制的方法
查看>>
ASP.NET实现类似Excel的数据透视表
查看>>
js在IE与firefox的差别。。。
查看>>
数据库事务的四大特性以及事务的隔离级别
查看>>
html4与html5的区别及html5的一些新特性
查看>>
2018年牛客多校算法寒假训练营练习比赛(第一场)C. 六子冲
查看>>
版本工具管理之----git
查看>>
JavaEE基础(二十四)/多线程
查看>>
利用httpd.ini和.htaccess的Rewrite实现301域名重定向
查看>>
EZ 2017 01 07 t
查看>>
阿里开源分布式事务解决方案 Fescar 全解析
查看>>
python-twisted系列(1)
查看>>