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

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

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 Input15 101 2 3 4 55 4 3 2 1Sample Output14

********************************************

分析:背包模型

1 #include 
2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 using namespace std;10 11 #define N 250012 #define INF 0x3f3f3f3f13 14 int p[N],v[N],dp[25000];15 16 int main()17 {18 int T,n,m,i,j;19 20 scanf("%d", &T);21 22 while(T--)23 {24 memset(dp,0,sizeof(dp));25 26 scanf("%d %d",&n, &m);27 28 for(i=1;i<=n;i++)29 scanf("%d", &p[i]);30 for(i=1;i<=n;i++)31 scanf("%d", &v[i]);32 33 for(i=1;i<=n;i++)34 for(j=m;j>=v[i];j--)35 dp[j]=max(dp[j],dp[j-v[i]]+p[i]);36 37 printf("%d\n", dp[m]);38 }39 return 0;40 }

 

转载于:https://www.cnblogs.com/weiyuan/p/5775306.html

你可能感兴趣的文章
[BZOJ4303]数列
查看>>
一般处理程序在VS2012中打开问题
查看>>
C语言中的++和--
查看>>
thinkphp3.2.3入口文件详解
查看>>
POJ 1141 Brackets Sequence
查看>>
Ubuntu 18.04 root 使用ssh密钥远程登陆
查看>>
Servlet和JSP的异同。
查看>>
虚拟机centOs Linux与Windows之间的文件传输
查看>>
ethereum(以太坊)(二)--合约中属性和行为的访问权限
查看>>
IOS内存管理
查看>>
middle
查看>>
[Bzoj1009][HNOI2008]GT考试(动态规划)
查看>>
Blob(二进制)、byte[]、long、date之间的类型转换
查看>>
OO第一次总结博客
查看>>
day7
查看>>
iphone移动端踩坑
查看>>
vs无法加载项目
查看>>
Beanutils基本用法
查看>>
玉伯的一道课后题题解(关于 IEEE 754 双精度浮点型精度损失)
查看>>
《BI那点儿事》数据流转换——百分比抽样、行抽样
查看>>