原题链接:https://www.acwing.com/problem/content/5/
#include <iostream>
#include <vector>
using namespace std;
const int N = 2010;
int dp[N];
struct Good {
int v, w;
};
int main() {
vector<Good> goods;
int n, m;
cin >> n >> m;
int v, w, s;
for (int i = 0; i < n; i ++) {
cin >> v >> w >> s;
for (int k = 1; k <= s; k *= 2 ) { //先二进制拆解
s -= k;
goods.push_back({v * k, w * k});
}
if (s > 0) { //多出来的数,直接使用
goods.push_back({v * s, w * s});
}
}
for (auto good: goods) {
for (int i = m; i >= good.v; i --) {
dp[i] = max(dp[i], dp[i - good.v] + good.w);
}
}
cout << dp[m] << endl;
return 0;
}