Bzoj1606: [usaco2008 DEC] hay for sale buy hay

Source: Internet
Author: User
1606: [usaco DEC] hay for sale hay purchase time limit: 5 sec memory limit: 64 MB
Submit: 612 solved: 463
[Submit] [Status] Description John suffered a major loss: cockroaches ate all his hay, leaving a group of ELE. Me cows. he took a carriage with a capacity of C (1 ≤ C ≤ 50000) and went to the house to buy some hay. because of the hay package of H (1 ≤ h ≤ 5000), each package has its volume VI (L ≤ VI ≤ C ). john can only buy the whole package. How much hay can he transport at most? Input 1st rows input C and h, and then H rows input a line VI. Output maximum purchased hay volume. Sample input7 3 // total volume is 7, use 3 items to carry a backpack
2
6
5


The wagon holds 7 volumetric units; three bales are offered for sale
Volumes of 2, 6, and 5 units, respectively.

Sample output7 // maximum size that can be backed up

Hint

 

Buying the two smaller bales fills the wagon.

 

Source

Silver

Question: Determining backpack... Are you still taking this test in the U.S. in? Code:
 1 var 2     i,j,m,x,n:longint; 3     f:array[0..100000]of boolean; 4 begin 5         assign(input,‘input.txt‘);assign(output,‘output.txt‘); 6         reset(input);rewrite(output); 7         readln(m,n); 8         f[0]:=true; 9     for i:=1 to n do10     begin11       readln(x);12       for j:=m downto x do13        f[j]:=f[j] or (f[j-x]);14     end;15     for i:=m downto 0 do if f[i] then break;16         writeln(i);17         close(input);close(output);18 end.19         
View code

 

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.