zoukankan      html  css  js  c++  java
  • BZOJ1618: [Usaco2008 Nov]Buying Hay 购买干草

    【传送门:BZOJ1618


    简要题意:

      有n个商店,要买h磅的食物

      每个商店给出p[i],c[i],表示第i个商店每一次买就会使用c[i]的费用,并得到p[i]磅食物

      求出买h磅或以上的最小费用


    题解:

      DP(完全背包)

      设f[i]为买i磅食物的最小费用,直接做就行了,水题


    参考代码:

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    #include<cstdlib>
    using namespace std;
    typedef long long LL;
    LL f[61000];
    int p[110];LL c[210];
    int main()
    {
        int n,h;
        scanf("%d%d",&n,&h);
        for(int i=1;i<=n;i++) scanf("%d%lld",&p[i],&c[i]);
        memset(f,63,sizeof(f));
        LL ans=999999999;
        f[0]=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=0;j<=h;j++)
            {
                f[j+p[i]]=min(f[j+p[i]],f[j]+c[i]);
                if(j+p[i]>=h) ans=min(ans,f[j+p[i]]);
            }
        }
        printf("%lld
    ",ans);
        return 0;
    }

     

  • 相关阅读:
    C语言01
    C++面试总结更新
    Python网络爬虫与信息提取02
    Self-Driving Car 01
    Python网络爬虫与信息提取01
    Python-03
    Shell
    Python-05
    Python-04
    Python-02
  • 原文地址:https://www.cnblogs.com/Never-mind/p/8666312.html
Copyright © 2011-2022 走看看