HDU 2602 Bone Collector "01 Backpack template"

Source: Internet
Author: User

Bone Collector

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 40404 Accepted Submission (s): 16786


Problem Descriptionmany years ago, in Teddy ' s hometown there is a man who was called "Bone Collector". 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 he trip of collecting there is a lot of bones, obviously , different bone have different value and different volume, now given the each bone's value along his trips, can you CALCU Late 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 both integer n, V, (N <=, v <=) repr Esenting 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 for each bone.
Outputone integer per line representing the maximum of the total value (this number would be is less than 231).
Sample Input
15 101 2 3 4 55 4 3 2 1

Sample Output
14

Authorteddy
Sourcehdu 1st "Vegetable-birds Cup" programming Open Contest Code:
HDU 2602 Bone collector#include <stdio.h> #include <string.h> #include <algorithm> #define MAX (A, B) ( A>B?A:B) using namespace std;struct inin{int val;//value! int cos;//Volume! }boy[10001];int bag[10001];//the size of the table below a number of items total value! int main () {int T;int n,v;//n represents the number of backpacks, V represents the overall product of the backpack! scanf ("%d", &t), while (t--) {memset (boy,0,sizeof (Boy)),//Save the value and volume of an item! memset (bag,0,sizeof (bag));//Save the total value of I items! scanf ("%d%d", &n,&v),//n represents the number of backpacks, V represents the overall product of the backpack! for (int i=1;i<=n;i++) {scanf ("%d", &boy[i].val);//value}for (int j=1;j<=n;j++) {scanf ("%d", &boy[j].cos); /volume}for (int i=1;i<=n;i++) {for (int j=v;j>=boy[i].cos;j--)//The maximum value {Bag[j]=max (Bag[j],bag[j-boy[i]) that the backpack can load from the back forward. Cos]+boy[i].val);//See Put and do not put the article I item of his value which large, choose the value of larger put into the array bag inside}//meaning is not put on the basis of the largest volume of the present and not put, It is only on the basis of your current volume minus the volume of the backpack you are going to put on the largest amount of value that can be accommodated! }printf ("%d\n", Bag[v]);//Finally, after all the items have been traversed, the last greatest value is the request! }return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU 2602 Bone Collector "01 Backpack template"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.