Hdu2602bone Collector Simple 0-1 backpack

Source: Internet
Author: User

Bone Collector

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


Problem Description

Many years ago, in Teddy ' s hometown there is a man whowas called "Bone Collector". Collect varies of bones, such asdog ' 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 Collectingthere is a lot of bones, obviously , different bone have different value anddifferent volume, now given the each bone ' s value along his trip, can Youcalculat E 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 Twointeger N, V, (N <=, v <=) repre Senting the number of Bonesand the volume of his bag. And the second line contain N integers representingthe value of each bone. The third line contain N integers representing thevolume of each bone.

Output

One integer per line representing the maximum of Thetotal value (this number would be is less than 231).

Sample Input

1

5 10

1 2 3) 4 5

5 4 3) 2 1

Sample Output

14

Note: Enter the value of each bone first and then enter the volume of each bone.

State transition equation: Dp[j]=max (dp[j],dp[j-v[i]]+w[i].

#include <iostream>#include<string.h>using namespacestd;intn,v;intdp[1111];intw[1111],v[1111];intMain () {intT;  while(cin>>t) {         while(t--) {cin>>N>>V;  for(intI=1; i<=n;i++) {cin>>W[i]; }             for(intI=1; i<=n;i++) {cin>>V[i]; } memset (DP,0,sizeof(DP));  for(intI=1; i<=n;i++){                 for(intj=v;j>=v[i];j--) {//J if less than v[i] then v[i] must not be loaded into the bagDp[j]=max (dp[j],dp[j-v[i]]+W[i]); }} cout<<dp[V]<<Endl; }    }    return 0;}

Hdu2602bone Collector Simple 0-1 backpack

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.