首页 > 其他 > 详细

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

时间:2019-03-22 13:51:40      阅读:177      评论:0      收藏:0      [点我收藏+]

题面: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

 

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!