Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
146022 | 王容宇 | 储钱罐 | C++ | 解答错误 | 40 | 1 MS | 300 KB | 908 | 2024-05-06 22:16:31 |
#include <bits/stdc++.h> using namespace std; struct str { int w, v; double wv; bool operator < (const str &o) const { if(wv==o.wv) { return wv<o.wv; } return w>o.w; } } s[501]; int n; bool b = true; void a1(int now, int x, int sum) { if(b==false) { return; } if(x==n+1) { if(now==0) { cout << "The minimum amount of money in the piggy-bank is " << sum << "." << endl; b=false; } return; } for(int i = now/s[x].w; i>=0; i--) { a1(now-s[x].w*i, x+1, sum+s[x].v*i); } } int main() { int t; cin >> t; for(int i = 1; i<=t; i++) { int w1, w2; cin >> w1 >> w2; int w = w2-w1; cin >> n; for(int j = 1; j<=n; j++) { cin >> s[j].v >> s[j].w; s[j].wv=s[j].v*1.0/s[j].w; } sort(s+1, s+n+1); a1(w, 1, 0); if(b) { cout << "This is impossible." << endl; } b=true; } return 0; }