Hdu 2602 (dp), hdu2602dp

Source: Internet
Author: User

Hdu 2602 (dp), hdu2602dp

Reference page:

Http://www.yuanjiaocheng.net/CSharp/Csharp-keys.html

Http://www.yuanjiaocheng.net/CSharp/csharp-interface.html

Http://www.yuanjiaocheng.net/CSharp/Csharp-operators.html

Http://www.yuanjiaocheng.net/CSharp/Csharp-if-else.html

Http://www.yuanjiaocheng.net/CSharp/Csharp-ternary-operator.html

Question link: http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 2602

 

 

Bone Collector

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


Problem Description policyears 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, obviusly, 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 instances.
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 2 31 ).

 

Sample Input 1 5 10 1 2 3 4 5 4 3 2 1

 

Sample Output 14: give you the size of a pack, the value of each bone and the volume occupied, and find the value that can be placed into the maximum value solution. Analysis: the simple 01 backpack is purely a template question. It is also my first question backpack, And I directly paste the code.
1 # include <cstdio> 2 # include <cmath> 3 # include <cstring> 4 # include <algorithm> 5 using namespace std; 6 7 // dp [I] [j] indicates the maximum value of placing the I-th bone and occupying j size, 8 // c [I] indicates the size of the I-th bone 9 // w [I] indicates the value of the I-th bone 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", & 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]; // here we mainly consider that when j is smaller than c [I], the I-th bone 31 if (j> = c [I]) cannot be placed. 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

 

Related Article

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.