Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
145457 梁颢城 储钱罐 C++ 通过 100 1 MS 300 KB 719 2024-05-05 09:01:39

Tests(5/5):


#include<bits/stdc++.h> const int INF=0x3f3f3f3f; using namespace std; int dp[10001]; int w[501],v[501]; int main() { int t; cin>>t; while(t--) { memset(dp,INF,sizeof(dp)); memset(w,0,sizeof(w)); memset(v,0,sizeof(v)); int m0,m,n; cin>>m0>>m>>n; m-=m0; for(int i=1;i<=n;i++) cin>>v[i]>>w[i]; dp[0]=0; for(int i=1;i<=n;i++) for(int j=w[i];j<=m;j++) if(dp[j-w[i]]!=INF) dp[j]=min(dp[j],dp[j-w[i]]+v[i]); 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; }


测评信息: