• 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]);

            

        }

    }

  • 相关阅读:
    Educational Codeforces Round 67 D. Subarray Sorting
    2019 Multi-University Training Contest 5
    Educational Codeforces Round 69 (Rated for Div. 2) E. Culture Code
    Educational Codeforces Round 69 D. Yet Another Subarray Problem
    2019牛客暑期多校训练第六场
    Educational Codeforces Round 68 E. Count The Rectangles
    2019牛客多校第五场题解
    2019 Multi-University Training Contest 3
    2019 Multi-University Training Contest 2
    [模板] 三维偏序
  • 原文地址:https://www.cnblogs.com/mltang/p/8720376.html
Copyright © 2020-2023  润新知