Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
146826 | 陈家宝 | 储钱罐 | C++ | 通过 | 100 | 42 MS | 19992 KB | 605 | 2024-05-14 16:21:00 |
#include<bits/stdc++.h> using namespace std; int p[505],w[505],dp[505][10005]; void slove(){ int e,f,n; cin>>e>>f>>n; f -= e; for (int i = 1;i <= n;i++)cin>>p[i]>>w[i]; memset(dp,0x3f3f3f3f,sizeof(dp)); dp[0][0] = 0; for (int i = 1;i <= n;i++)for (int j = 0;j <= f;j++)for (int k = 0;k * w[i] <= j;k++)dp[i][j] = min(dp[i][j],dp[i - 1][j - k * w[i]] + k * p[i]); if (dp[n][f] >= 0x3f3f3f3f)cout<<"This is impossible.\n"; else cout<<"The minimum amount of money in the piggy-bank is "<<dp[n][f]<<".\n"; return ; } int main(){ int t; cin>>t; while (t--)slove(); return 0; }