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

首頁 > 學院 > 開發設計 > 正文

hdu 2602(dp)

2019-11-17 02:42:03
字體:
來源:轉載
供稿:網友

hdu 2602(dp)

題目鏈接 :http://acm.hdu.edu.cn/showPRoblem.php?pid=2602

Bone Collector

Time Limit: 2000/1000 MS (java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 32499Accepted Submission(s): 13379

Problem DescriptionMany 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 ?

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

OutputOne integer per line representing the maximum of the total value (this number will be less than 231).

Sample Input1 5 10 1 2 3 4 5 5 4 3 2 1

Sample Output14題意 :給你一個包的體積,每塊骨頭的價值和占用的體積,求出可以放入價值最大方案的價值。分析 :簡單的01背包,純屬模板題,也是我做的第一題背包,就直接貼代碼了。
 1 #include <cstdio> 2 #include <cmath> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6  7 //dp[i][j]表示放入第i塊骨頭并占用j體積的最大價值, 8 //c[i]表示第i塊骨頭的體積 9 //w[i]表示第i塊骨頭的價值10 11 int dp[1111][1111],c[1111],w[1111];12 int T,N,V;13 14 int main ()15 {16     int i,j;17     scanf ("%d",&T);18     while (T--)19     {20         scanf ("%d%d",&N,&V);21         for (i=1; i<=N; i++)22         scanf ("%d",&w[i]);23         for (i=1; i<=N; i++)24         scanf ("%d",&c[i]);25         memset(dp, 0, sizeof(dp));26         for (i=1; i<=N; i++)27         {28             for (j=0; j<=V; j++)29             {30                 dp[i][j] = dp[i-1][j];   //這里主要考慮j小于c[i]時放不下第i塊骨頭31                 if (j >= c[i])32                 dp[i][j] = max(dp[i-1][j], dp[i-1][j-c[i]]+w[i]);33             }34         }35         printf ("%d/n",dp[N][V]);36     }37     return 0;38 }
View Code


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 柳江县| 呼图壁县| 麻江县| 旬阳县| 山东| 高阳县| 闸北区| 东城区| 井研县| SHOW| 溧水县| 梁河县| 崇文区| 赞皇县| 格尔木市| 海盐县| 揭西县| 湾仔区| 兴城市| 永胜县| 大化| 崇信县| 天祝| 云梦县| 靖边县| 房产| 分宜县| 泸水县| 刚察县| 酉阳| 普兰店市| 宜良县| 治多县| 通化市| 隆尧县| 内乡县| 清水河县| 定日县| 图们市| 乌鲁木齐县| 原平市|