Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
145448 | 你女子 | 储钱罐 | C++ | 通过 | 100 | 2 MS | 416 KB | 795 | 2024-05-05 08:49:19 |
#include<bits/stdc++.h> using namespace std; long long T,e,g,n,m,w[10005],v[10005],f[10005],dp[10005]; const long long inf=550000; int main(){ cin>>T; while(T--){ memset(dp,inf,sizeof(dp)); memset(f,inf,sizeof(f)); dp[0]=0; cin>>e>>g; m=g-e; cin>>n; for(int i=1;i<=n;i++){ cin>>v[i]>>w[i]; } for(int i=1;i<=m;i++){ for(int j=1;j<=n;j++){ if(i>=w[j]){ dp[i]=min(dp[i],v[j]+dp[i-w[j]]); } } } // for(int i=1;i<=m;i++){ // for(int j=1;j<=n;j++){ // if(i>=w[j]){ // f[i]=min(f[i],w[j]+f[i-w[j]]); // } // } // } // cout<<f[m]<<endl; if(dp[m]<inf){ cout<<"The minimum amount of money in the piggy-bank is "<<dp[m]<<"."<<endl; } else{ cout<<"This is impossible."<<endl; } } return 0; }