国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

Bone Collector

2019-11-08 02:41:08
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

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

Example Input

15 101 2 3 4 55 4 3 2 1

Example Output

14題意大概:第一行輸入測(cè)試數(shù)據(jù)的組數(shù)。 第二行輸入骨頭的個(gè)數(shù)和自己背包的體積。  第三行輸入每個(gè)骨頭的價(jià)值。  第四行輸入每個(gè)骨頭的體積。  輸出可以獲得的最大價(jià)值。此題為背包問(wèn)題中的一種,一個(gè)物品只能拿一次,求最大獲得價(jià)值。
#include<stdio.h>#include<string.h>int df[1000];int max(int a,int b){    return (a>b?a:b);}int main(){    int t,i,j,n,v;    int p[1000],w[1000];    scanf("%d",&t);    while(t--)    {        memset(df,0,sizeof(df));        scanf("%d%d",&n,&v);        for(i=0;i<n;i++)        {            scanf("%d",&p[i]);        }        for(i=0;i<n;i++)        {            scanf("%d",&w[i]);        }        for(i=0;i<n;i++)        {            for(j=v;j>=w[i];j--)            {                df[j]=max(df[j-w[i]]+p[i],df[j]);            }        }        printf("%d/n",df[v]);    }    return 0;}
發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 通渭县| 常熟市| 宁海县| 咸丰县| 安岳县| 宣威市| 绵阳市| 延寿县| 中西区| 石嘴山市| 花莲县| 隆安县| 梁平县| 阿巴嘎旗| 运城市| 固阳县| 胶南市| 巴中市| 罗田县| 石棉县| 神木县| 启东市| 图木舒克市| 五峰| 始兴县| 阳新县| 清徐县| 沧州市| 平塘县| 望江县| 棋牌| 永川市| 玉田县| 溆浦县| 永登县| 介休市| 延长县| 静海县| 海原县| 封开县| 上高县|