Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
145464 苏唯哲 储钱罐 C++ 解答错误 60 1 MS 256 KB 532 2024-05-05 09:07:23

Tests(3/5):


#include<bits/stdc++.h> using namespace std; int t,e,f,n,p[501],w[501],dp[501]; int main(){ cin>>t; while(t--){ cin>>e>>f>>n; for(int i=0;i<n;i++){ cin>>p[i]>>w[i]; } int v=f-e; dp[0]=0; for(int i=1;i<=v;i++){ dp[i]=0x3f3f3f3f; } for(int i=0;i<n;i++){ for(int j=w[i];j<=v;j++){ dp[j]=min(dp[j],dp[j-w[i]]+p[i]); } } if(dp[v]!=0x3f3f3f3f){ cout<<"The minimum amount of money in the piggy-bank is "<<dp[v]<<"."<<endl; }else cout<<"This is impossible."<<endl; } }


测评信息: