HDU-1114-Piggy-Bank(完全背包)

 1 #include<iostream>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 const int maxn=2*10*1000;
 6 const int inf=0x7f7f7f7f;
 7 int t,e,f,n,m,a,b;
 8 int dp[maxn];
 9 int main()
10 {
11     ios::sync_with_stdio(false);
12     cin>>t;
13     while(t--)
14     {
15         memset(dp,0x7f,sizeof(dp));
16         cin>>e>>f;
17         m=f-e;
18         cin>>n;
19         dp[0]=0;
20         for(int i=0;i<n;i++)
21         {
22             cin>>a>>b;
23             for(int j=b;j<=m;j++)
24             {
25                 dp[j]=min(dp[j],dp[j-b]+a);
26             }
27         }
28         if(dp[m]==inf)
29         {
30             cout<<"This is impossible."<<endl;
31         }
32         else
33         {
34             cout<<"The minimum amount of money in the piggy-bank is "<<dp[m]<<'.'<<endl;
35         }
36     }
37     return 0;
38 }

 

posted @ 2020-02-05 11:26  STL_CC  阅读(90)  评论(0)    收藏  举报