码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-02-07 12:03:20      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:center   填充   com   zoj   enter   blog   math   pos   can   

【传送门:BZOJ1606


简要题意:

  给出一个有容量的背包,和许多物品,物品有体积,请问最多能填充多大的容量


题解:

  经典背包DP,裸题,不说话


参考代码:

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;  
int n,m,a[5100],f[51000];  
int main()  
{  
    scanf("%d%d",&m,&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);  
    for(int i=1;i<=n;i++)
    {
        for(int j=m;j>=a[i];j--)
        {
               f[j]=max(f[j],f[j-a[i]]+a[i]);
           }
    }
    printf("%d",f[m]);  
    return 0;  
}  

 

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

标签:center   填充   com   zoj   enter   blog   math   pos   can   

原文地址:https://www.cnblogs.com/Never-mind/p/8425409.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!