• hdu 1114


    完全背包问题

    让你尽可能的少装价值,装满背包

    就把dp[0]=0即可,其他变成inf,然后就是标准的完全背包问题

    代码:

    #include <iostream>

    #include <algorithm>

    #include <cstring>

    #include <cstdlib>

    using namespace std;

    const int maxn = 1e6+5;

    long long dp[maxn];

    int w[maxn],v[maxn];

    int main()

    {

        int i,j,t,a,b,c,n,k;

        scanf("%d",&t);

        while(t--)

        {

            scanf("%d%d",&a,&b);

            scanf("%d",&n);

            for(i = 1; i <= n; ++i)

                scanf("%d%d",v+i,w+i);

            

            c = b-a;

            dp[0] = 0;

            for(i = 1; i <= c; ++i)

                dp[i] = 100000000;

            for(i = 1; i <= n;++i)

            {

                for(j = w[i];j <= c; ++j)

                {

                    dp[j] = min(dp[j],dp[j-w[i]]+v[i]);

                }

            }

            

            if(dp[c]==100000000)

                printf("This is impossible. ");

            else

                printf("The minimum amount of money in the piggy-bank is %lld. ",dp[c]);

            

        }

    }

  • 相关阅读:
    模仿.Net ThreadPool的线程池控件
    ThreadPool for Delphi
    Thread Pool Engine, and Work-Stealing scheduling algorithm
    Delphi ThreadPool 线程池(Delphi2009以上版本适用)
    Object Pascal对象模型中构造函数之研究
    TExternalThread TThread -- Delphi -- Cannot terminate an externally created thread ?
    Trapping Messages Sent to an Application
    Correct thread terminate and destroy
    Delphi thread exception mechanism
    VCL -- Understanding the Message-Handling System
  • 原文地址:https://www.cnblogs.com/mltang/p/8720376.html
Copyright © 2020-2023  润新知