Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
145444 | 赵德明 | 储钱罐 | C++ | 通过 | 100 | 2 MS | 460 KB | 610 | 2024-05-05 08:40:06 |
#include<bits/stdc++.h> using namespace std; const long long inf=5500000; signed main(){ int T,n,m,a[50005],b[50005],dp[50005];//第i项表示容量为i时最值 int e,f; cin>>T; for(int t=1;t<=T;t++){ memset(dp,inf,sizeof(dp)); dp[0]=0; cin>>m>>n; cin>>e; f=n-m; for(int i=1;i<=e;i++){ cin>>b[i]>>a[i]; } for(int i=1;i<=f;i++){ for(int j=1;j<=e;j++){ if(i-a[j]>=0) dp[i]=min(dp[i-a[j]]+b[j],dp[i]); } } if(dp[f]<inf) cout<<"The minimum amount of money in the piggy-bank is "<<dp[f]<<"."<<endl; else cout<<"This is impossible."<<endl; } }