题意:
三种物品,<重量,费用> 分别为 \(<1,X>,<A,Y>,<B,Z>\),求恰凑出重量 \(n\) 的最小费用
\(T\le 100, 1\le n,A,B,X,Y,Z\le 1e9\)
思路:
https://blog.csdn.net/qq_45863710/article/details/124400676
void sol() {
ll n; cin >> n;
vector<pair<ll, ll> > a(3); // val,cost
#define v first
#define c second
a[0].v = 1; cin >> a[1].v >> a[2].v >> a[0].c >> a[1].c >> a[2].c;
sort(a.begin(), a.end(), [](auto x, auto y) { //性价比从高到低
return x.v * y.c > y.v * x.c;
});
ll ans = 1e18;
if(a[0].v == 1) ans = n * a[0].c;
else if(a[1].v == 1) ans = n / a[0].v * a[0].c + n % a[0].v * a[1].c;
else {
ll lim = n / a[0].v;
if(lim > a[0].v - 1) lim = a[0].v - 1, swap(a[0], a[1]);
for(ll i = 0; i <= lim; i++) {
ll r = n - i * a[0].v;
if(r >= 0) ans = min(ans,
i * a[0].c + r / a[1].v * a[1].c + r % a[1].v * a[2].c);
}
}
cout << ans << '\n';
}
标签:le,lim,Make,arc139,ans,ll,define
From: https://www.cnblogs.com/wushansinger/p/17069482.html