[BZOJ1606] [Usaco2008 Dec] Hay for Sale Purchase (DP)

Source: Internet
Author: User

DescriptionJohn suffered a major loss: the cockroach ate all his hay and left a herd of hungry cows.  He rode a carriage in C (1≤c≤50000), and went to the house to buy some hay. Because of the H (1≤h≤5000) bales of hay, each pack has its volume Vi (l≤vi≤c). John can only buy the whole package, how many volumes of hay will he be able to ship back?InputEnter C and h in line 1th, then enter a VI on line H.OutputThe largest volume of available hay.Sample Input7 3//Total volume of 7, with 3 items to backpack
2
6
5
The wagon holds 7 volumetric units; Three bales is offered for sale with
Volumes of 2, 6, and 5 units, respectively.
Sample Output7//maximum volume that can be backed up
HINT

Buying The smaller bales fills the wagon.

Source

Silver

Solution

Violence DP can be water I'll talk nonsense?

1#include <bits/stdc++.h>2 using namespacestd;3 inta[5005];4 BOOLf[50005];5 intMain ()6 {7     intans, C, H;8scanf"%d%d", &c, &h);9      for(inti =1; I <= H; i++)Tenscanf"%d", A +i); Onef[0] =true; A      for(inti =1; I <= H; i++) -          for(intj = C-a[i]; ~j; j--) -             if(F[j]) F[j + a[i]] =true; the      for(inti =1; I <= C; i++) -         if(F[i]) ans =i; -printf"%d\n", ans); -     return 0; +}
View Code

[BZOJ1606] [Usaco2008 Dec] Hay for Sale Purchase (DP)

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.