HDU2602
来源:互联网 发布:php语言精粹 编辑:程序博客网 时间:2024/05/19 23:59
Bone Collector
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 52183 Accepted Submission(s): 21988
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 ?
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.
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 231).
Sample Input
15 101 2 3 4 55 4 3 2 1
Sample Output
140-1背包练手容量为V的袋子,每个骨头有其体积和价值问最大价值为多少。动态转移方程:if (dp[j-vol[i]]+val[i]>dp[j]) dp[j]=dp[j-vol[i]]+val[i];#include <cstdio>#include <string.h>const int MAX=1005;int dp[1005],val[MAX],vol[MAX];int main(){ int T,n,v,i,j; scanf("%d",&T); while(T--) { memset(dp,0,sizeof(dp)); scanf("%d%d",&n,&v); for(i=1;i<=n;i++) scanf("%d",&val[i]); for(i=1;i<=n;i++) scanf("%d",&vol[i]); for(i=1;i<=n;i++) for(j=v;j>=vol[i];j--) if (dp[j-vol[i]]+val[i]>dp[j]) dp[j]=dp[j-vol[i]]+val[i]; printf("%d\n",dp[v]); } return 0;}
0 0
- hdu2602
- hdu2602
- hdu2602
- hdu2602
- hdu2602
- HDU2602
- hdu2602
- hdu2602
- HDU2602
- hdu2602
- HDU2602
- HDU2602
- HDU2602
- HDU2602
- hdu2602
- HDU2602二维
- hdu2602 java
- hdu2602!01背包问题
- Struts2+Spring+Hibernate3集成
- 新出炉的最全手机自适应布局格式(亲测有效)
- 2016新手seo应该如何做高质量的外链
- 树状数组(Garlands,codeforces 707e)
- VS2010 SP1安装卡在VS10Sp1-KB983509处的解决(转)
- HDU2602
- 计算机中的二进制表示-4和5
- 几种线程池的实现算法分析
- Bitmap的深入理解
- retrofit2.0+okhttp3+rxjava的封装(简单好用)
- (开发笔记)转载:eclipse maven 插件 自动生成mybatis dao、mapper
- Handler、Looper、Message、MessageQueue
- IOS-70-emoji表情键盘(防微信,实现自定义文字、表情相互转化,附demo)
- Nginx深入详解之upstream分配方式