"Bzoj 1606" [Usaco2008 dec]hay for Sale buy hay 01 backpack

Source: Internet
Author: User

1606: [Usaco2008 dec]hay for Sale buy hay
Time Limit:5 Sec Memory limit:64 MB
submit:978 solved:735
[Submit] [Status] [Discuss]
Description

约翰遭受了重大的损失:蟑螂吃掉了他所有的干草,留下一群饥饿的牛.他乘着容量为C(1≤C≤50000)个单位的马车,去顿因家买一些干草.  顿因有H(1≤H≤5000)包干草,每一包都有它的体积Vi(l≤Vi≤C).约翰只能整包购买,

How many volumes of hay can he transport back?

Input

第1行输入C和H,之后H行一行输入一个Vi.

Output

最多的可买干草体积.

Sample Input

7 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 Output

7//maximum volume that can be backed up

idea : 01 knapsack judgment feasibility;

Code :

#include <stdio.h>#include <iostream>using namespace STD;intf[50005];intv[5005];intMain () {intC,h;scanf("%d%d", &c,&h); for(intI=1; i<=h;i++)scanf("%d", &v[i]); f[0]=1; for(intI=1; i<=h;i++) { for(intj=c;j>=v[i];j--)if(f[j-v[i]]==1) f[j]=1; } for(inti=c;i>=0; i--) {if(F[i]) {cout<<i<<endl;return 0; }    }}

"Bzoj 1606" [Usaco2008 dec]hay for Sale buy hay 01 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.