0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-16 20:05:26 +00:00

5. 多重背包问题 II

https://www.acwing.com/problem/content/submission/code_detail/13024172/
This commit is contained in:
Baoshuo Ren 2022-04-05 19:19:33 +08:00
parent a189995d60
commit 3a25292160
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

36
AcWing/5/5.cpp Normal file
View File

@ -0,0 +1,36 @@
#include <iostream>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int M = 2005;
int n, m, f[M];
std::vector<std::pair<int, int>> a;
int main() {
std::ios::sync_with_stdio(false);
cin >> n >> m;
for (int i = 1, v, w, s; i <= n; i++) {
cin >> v >> w >> s;
for (int k = 1; k <= s; k <<= 1) {
s -= k;
a.push_back(std::make_pair(k * v, k * w));
}
if (s > 0) a.push_back(std::make_pair(s * v, s * w));
}
for (int i = 0; i < a.size(); i++) {
for (int j = m; j >= a[i].first; j--) {
f[j] = std::max(f[j], f[j - a[i].first] + a[i].second);
}
}
cout << f[m] << endl;
return 0;
}