Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
145431 | 李树强 | 储钱罐 | C++ | 通过 | 100 | 2 MS | 304 KB | 612 | 2024-05-05 08:28:03 |
#include<iostream> using namespace std; const int N = 1e2 * 5 + 10, M = 1e4 + 10, inf = 1e9; int t, a, b, n, v[N], w[N], f[M]; int main(){ cin >> t; while(t--){ for(int i = 0; i < M; i++) f[i] = inf; cin >> a >> b >> n; for(int i = 0; i < n; i++) cin >> v[i] >> w[i]; b -= a; f[0] = 0; for(int i = 0; i < n; i++){ for(int j = 0; j <= b; j++){ if(j >= w[i]) f[j] = min(f[j], f[j-w[i]] + v[i]); } } if(f[b] == inf) cout << "This is impossible." << endl; else cout << "The minimum amount of money in the piggy-bank is " << f[b] << "."<< endl; } return 0; }