zoukankan      html  css  js  c++  java
  • hdu 1114 Piggy-Bank

    http://acm.hdu.edu.cn/showproblem.php?pid=1114

    完全背包。

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <algorithm>
     4 #define maxn 50000
     5 using namespace std;
     6 const int inf=1<<28;
     7 
     8 int dp[maxn];
     9 int p[maxn],w[maxn];
    10 int t,n,e,f;
    11 
    12 int main()
    13 {
    14     scanf("%d",&t);
    15     while(t--)
    16     {
    17         scanf("%d%d",&e,&f);
    18         scanf("%d",&n);
    19         for(int i=1; i<=n; i++)
    20         {
    21             scanf("%d%d",&p[i],&w[i]);
    22         }
    23         for(int j=1; j<=f-e; j++)
    24         {
    25             dp[j]=inf;
    26         }
    27         dp[0]=0;
    28         for(int i=1; i<=n; i++)
    29         {
    30             for(int j=w[i]; j<=f-e; j++)
    31             {
    32                 dp[j]=min(dp[j],dp[j-w[i]]+p[i]);
    33             }
    34         }
    35         if(dp[f-e]==inf)
    36             printf("This is impossible.
    ");
    37         else
    38             printf("The minimum amount of money in the piggy-bank is %d.
    ",dp[f-e]);
    39     }
    40     return 0;
    41 }
    View Code
  • 相关阅读:
    bzoj2467 [中山市选2010]生成树
    hdu4489 The King’s Ups and Downs
    hdu4489 The King’s Ups and Downs
    Tyvj1014(区间dp)
    Tyvj1014(区间dp)
    Tyvj1013
    Tyvj1013
    Tyvj1009
    22.引用指针
    21.引用指针
  • 原文地址:https://www.cnblogs.com/fanminghui/p/3878193.html
Copyright © 2011-2022 走看看