Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
145460 | 吴松韬 | 储钱罐 | C++ | 通过 | 100 | 1 MS | 256 KB | 562 | 2024-05-05 09:02:47 |
#include<bits/stdc++.h> using namespace std; int f[10001]; int e,p,t,n; int w[501]; int v[501]; int main(){ cin>>t; for(int k=1;k<=t;k++){ cin>>e>>p; int m=p-e; f[0]=0;cin>>n; for(int i=0;i<n;i++){ cin>>v[i]>>w[i]; } for(int i=1;i<=m;i++){ f[i]=1E9; } for(int i=0;i<n;i++){ for(int j=w[i];j<=m;j++){ f[j]=min(f[j],f[j-w[i]]+v[i]); } } if(f[m]<1E9){ cout<<"The minimum amount of money in the piggy-bank is "<<f[m]<<"."<<endl; }else{ cout<<"This is impossible."<<endl; } } return 0; }