杭电oj(Java版)2602 Bone Collector 01背包问题
来源:互联网 发布:服务器端软件开发 编辑:程序博客网 时间:2024/06/02 00:53
Bone Collector
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 60730 Accepted Submission(s): 25315
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 ?
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.
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
import java.util.Scanner;public class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int nums=sc.nextInt(); for(int i=0;i<nums;i++){ int count=sc.nextInt(); int weight=sc.nextInt(); int[] weigh=new int[count]; int[] value=new int[count]; for(int j=0;j<count;j++){ value[j]=sc.nextInt(); } for(int j=0;j<count;j++){ weigh[j]=sc.nextInt(); } backBag(weigh,value,weight); } } public static void backBag(int[] weigh, int[] value, int weight) { int[] dp=new int[weight+1]; for(int i=0;i<weigh.length;i++){ for(int j=weight;j>=weigh[i];j--){ dp[j]=Math.max(dp[j], dp[j-weigh[i]]+value[i]); } }System.out.println(dp[weight]);}}
0 0
- 杭电oj(Java版)—— 2602 Bone Collector—— 01背包问题
- 杭电oj(Java版)2602 Bone Collector 01背包问题
- 【杭电oj】2602 - Bone Collector(01背包)
- 杭电 2602 Bone Collector(背包问题 )
- Bone Collector(杭电2602)(01背包)
- ACM 杭电hdu 2602 Bone Collector(01背包)
- 杭电 2602 bone collector (01背包)
- 杭电2602Bone Collector(01背包)
- 杭电2602 Bone Collector(01背包)
- 杭电-2602 Bone Collector(01背包模板)
- 背包问题—杭电2602 Bone Collector
- HDU--杭电--2602--Bone Collector--背包
- 杭电ACM 2602 Bone Collector背包
- 杭电OJ2602--------Bone Collector---------01背包
- hdu oj 2602 Bone Collector(背包)
- 杭电2602--Bone Collector(01背包…
- 杭电 2603 Bone Collector(简单01背包)
- Hdu oj 2602 Bone Collector(01背包)
- Cocos-Js项目中自己写的 HashMap
- java异常Throwable和Sping事务控制的异常回滚
- leetcode-53. Maximum Subarray
- 终身机器学习(Lifelong Machine Learning)
- 2015年需要了解的前端框架和语言
- 杭电oj(Java版)2602 Bone Collector 01背包问题
- ITK4.11.1编译配置+VS2015+Cmake3.8.1
- python wget下载文件处理的一些问题
- FPGA状态机总结
- Buy a Shovel
- Windows Spark开发环境部署
- ==与===
- 比特币开发专题(交易平台基本原理和指南)
- 文件夹复制(拷贝)原理分析