10
14
2015
0

[BZOJ1606] [Usaco2008 Dec] Hay For Sale 购买干草

01背包模版题。

#include<cstdio>
#include<algorithm>
using namespace std;

int n,v,a[5005],f[50005];

int main(){
freopen("1606.in","r",stdin);
freopen("1606.out","w",stdout);
scanf("%d %d",&v,&n);
for(int i=1;i<=n;i++){
    scanf("%d",&a[i]);
}
for(int i=1;i<=n;i++){
    for(int j=v;j>=a[i];j--){
        f[j]=max(f[j],f[j-a[i]]+a[i]);
    }
}
printf("%d\n",f[v]);
return 0;
}
Category: BZOJ | Tags: BZOJ | Read Count: 477

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter

Host by is-Programmer.com | Power by Chito 1.3.3 beta | Theme: Aeros 2.0 by TheBuckmaker.com