01背包 || BZOJ 1606: [Usaco2008 Dec]Hay For Sale 购买干草 || Luogu P2925 [USACO08DEC]干草出售Hay For Sale

题面:P2925 [USACO08DEC]干草出售Hay For Sale

题解:无

代码:

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 using namespace std;
 5 const int maxc=50050,maxh=5050;
 6 int C,H,V[maxh];
 7 bool F[maxc];
 8 int main(){
 9     scanf("%d%d",&C,&H);
10     for(int i=1;i<=H;i++)scanf("%d",&V[i]);
11     F[0]=1;
12     for(int i=1;i<=H;i++)
13         for(int j=C;j>=V[i];j--)
14             if(F[j-V[i]])F[j]=1;
15     for(int i=C;i>=0;i--)
16         if(F[i]){
17             printf("%d
",i);
18             return 0;
19         }
20 }

By:AlenaNuna

原文地址:https://www.cnblogs.com/AlenaNuna/p/10577731.html