mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-08 12:58:48 +00:00
5. 多重背包问题 II
https://www.acwing.com/problem/content/submission/code_detail/13024172/
This commit is contained in:
parent
a189995d60
commit
3a25292160
36
AcWing/5/5.cpp
Normal file
36
AcWing/5/5.cpp
Normal 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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user