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

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

Bone Collector

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

Total Submission(s): 11188    Accepted Submission(s): 4317

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 ?
HDOJ-2602 <wbr>Bone <wbr>Collector
 

 

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).
 
 
 
1 /*   2 //0-1背包问题,容量可以从前向后推(二维数组),也可以从后向前推(一维数组)  3  4 //代码一: 5 #include
6 #include
7 int main() 8 { 9 int t,V,i,j,N;10 int val[1001],vol[1001],record[1001];11 scanf("%d",&t);12 while(t--)13 {14 memset(record,0,sizeof(record));15 scanf("%d%d",&N,&V);16 for(i=0;i
=vol[i];--j)22 if(record[j-vol[i]]+val[i]>record[j])23 record[j]=record[j-vol[i]]+val[i];24 printf("%d\n",record[V]);25 }26 return 0;27 }28 29 30 //代码二:31 #include
32 #include
33 int main()34 {35 int t,V,i,j,N;36 int val[1001],vol[1001],record[1001];37 scanf("%d",&t);38 while(t--)39 {40 memset(record,0,sizeof(record));41 scanf("%d%d",&N,&V);42 for(i=0;i
=vol[i];--j)48 if(record[j-vol[i]]+val[i]>record[j])49 record[j]=record[j-vol[i]]+val[i];50 }51 printf("%d\n",record[V]);52 }53 return 0;54 }55 */56 57 //代码三: 二位数组的写法58 #include
59 #include
60 61 int val[1001],vol[1001];62 int dp[1001][1001];63 int main()64 {65 int T,i,j,n,v;66 scanf("%d",&T);67 while(T--)68 {69 scanf("%d%d",&n,&v);70 for(i=1;i<=n;++i)71 scanf("%d",&val[i]);72 for(i=1;i<=n;++i)73 scanf("%d",&vol[i]);74 memset(dp,0,sizeof(dp));75 for(i=1;i<=n;++i)76 for(j=0;j<=v;++j) //注意这里要从0开始77 if(j>=vol[i]) //背包容量能过装下第i件骨头的情况下选取装与不装的最大值78 dp[i][j]=dp[i-1][j]>dp[i-1][j-vol[i]]+val[i]?dp[i-1][j]:dp[i-1][j-vol[i]]+val[i];79 else //背包容量不能装下第i件的化当前最大值为装下前i-1件骨头的状态80 dp[i][j]=dp[i-1][j];81 printf("%d\n",dp[n][v]);82 }83 return 0;84 }

 

转载地址:http://krhcl.baihongyu.com/

你可能感兴趣的文章
通过selenium模拟键盘输入链接整理
查看>>
iOS 登录页面设计
查看>>
特殊权限set_uid set_gid stick_bit 软/硬链接文件
查看>>
企业分布式SpringCloud+SpringBoot+Mybatis+shiro+微服务 技术分享
查看>>
hibernate 查询条件 对象expression
查看>>
分布式事务
查看>>
Linux就该这么学 - 第四课 - 打包压缩~第3章重定向与环境变量
查看>>
简单的单臂路由的 配置实验(华为)
查看>>
技术和商业的碰撞,谈阿里云与天猫双11这十年
查看>>
智能家居应该怎样来维护和保养—成都首脑智能家居项目
查看>>
C语言100个经典算法源码片段
查看>>
精美流程图模板分享
查看>>
Cobbler
查看>>
手机照片误删怎么恢复?这两种专业方法可以试试看
查看>>
Struts2之2.5.10.1HelloWorld
查看>>
我的友情链接
查看>>
angularjs-常用angular函数
查看>>
我们如何来轻松部署Exchange
查看>>
模板实现双向链表
查看>>
浅谈RUP的9个核心工作流(Core Workflows)
查看>>