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

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

Bone Collector——01背包

2019-11-08 02:49:12
字體:
來源:轉載
供稿:網友

think: 1 01背包 2 注意c[]數組和w[]數組的輸入順序

sdut原題鏈接

Bone Collector Time Limit: 1000MS Memory Limit: 65536KB

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 1 5 10 1 2 3 4 5 5 4 3 2 1

Example Output 14

Hint hdoj2602

Author

以下為accepted代碼

#include <stdio.h>#include <string.h>#define Max(a, b) (a > b? a: b)int main(){ int T, n, v, c[1004], w[1004], dp[1004]; scanf("%d", &T); while(T--) { memset(dp, 0, sizeof(dp)); scanf("%d %d", &n, &v); for(int i = 0; i < n; i++) { scanf("%d", &w[i]); } for(int i = 0; i < n; i++) { scanf("%d", &c[i]); } for(int i = 0; i < n; i++) { for(int j = v; j >= c[i]; j--) { dp[j] = Max(dp[j], dp[j-c[i]] + w[i]); } } printf("%d/n", dp[v]); } return 0;}/***************************************************User name: Result: AcceptedTake time: 0msTake Memory: 120KBSubmit time: 2017-02-18 16:44:33****************************************************/
上一篇:Game!

下一篇:hdoj2037 今年暑假不AC

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 金门县| 纳雍县| 崇阳县| 红原县| 长海县| 隆化县| 新宾| 夏津县| 万盛区| 铁岭市| 遵义县| 宜阳县| 余庆县| 石门县| 阿拉善右旗| 隆子县| 抚宁县| 齐河县| 客服| 新宁县| 丹寨县| 岗巴县| 江门市| 上蔡县| 麦盖提县| 上虞市| 枞阳县| 桐乡市| 宜兴市| 恩平市| 观塘区| 昂仁县| 新平| 英吉沙县| 乡宁县| 巩义市| 富川| 陇川县| 苍溪县| 仪征市| 万山特区|