首页 > 其他分享> > 01背包 || BZOJ 1606: [Usaco2008 Dec]Hay For Sale 购买干草 || Luogu P2925 [USACO08DEC]干草出售Hay For Sale
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\n",i); 18 return 0; 19 } 20 }
By:AlenaNuna
标签:int,Sale,Hay,USACO08DEC,include,干草 来源: https://www.cnblogs.com/AlenaNuna/p/10577731.html