提交时间:2024-05-16 13:35:01

运行 ID: 147062

#include<iostream> using namespace std; int a,b,c,d,e,f[504],g[505],h,i[114514],j,k[11],l; int main() { cin>>a; for(b=1;b<=a;b++) { cin>>l>>c>>d; j=c-l; for(e=1;e<=d;e++) { cin>>g[e]>>f[e]; } i[1]=0; for(e=1;e<=j;e++) i[e]=1E9; for(e=1;e<=d;e++) for(h=f[e];h<=j;h++) i[h]=min(i[h],i[h-f[e]]+g[e]); k[b]=i[j]; } for(b=1;b<=a;b++) { if(k[b]<1E9) cout<<"The minimum amount of money in the piggy-bank is "<<k[b]<<"."<<endl; else cout<<"This is impossible."<<endl; } return 0; }