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 ?

 

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 231).
 

Sample Input
15 101 2 3 4 55 4 3 2 1
 

Sample Output
14
0-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
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 小米手机解锁图案忘了怎么办 红米2内屏坏了怎么办 红米密码忘记了怎么办 红米pro玩王者卡怎么办 红米note4不支持计步怎么办 红米pro玩游戏卡怎么办 红米手机费电快怎么办 荣耀5c忘记密码怎么办 小米之家不退货怎么办 手机号绑定过多小米账户怎么办 耐克黑色鞋褪色怎么办 买广汽传祺7s新车有问题怎么办 华为荣耀10边框掉色了怎么办 网购商家打来无货怎么办 客户拍了不发货怎么办 天猫商家欺骗买家怎么办 阿里买家投诉我发空包怎么办 苹果6s电池坏了怎么办 hm买的单鞋脏了怎么办 微店违规屏蔽搜索怎么办 ios微信支付失效怎么办 京东第三方店铺关闭怎么办 京东店铺关门了怎么办 国美退款不到账怎么办 小米小店通过了怎么办 苹果的发票丢了怎么办 苹果7p开不开机怎么办 申请退款了怎么卖家还发货怎么办 买家申请退款卖家不退款怎么办 卖家恶意不退款怎么办 欠条到期了对方不还钱怎么办 冰箱磕了一坑怎么办 办信用卡没有家庭地址的怎么办 钱付了货没收到怎么办 在苏宁易购上买东西地址错了怎么办 手机分期付款银行卡丢了怎么办 华硕笔记本鼠标不动了怎么办 韵达快递不派送怎么办 中通快递不派送怎么办 农业银行信用卡密码输错三次怎么办 农业银行卡多次输错密码怎么办