2020.12.30开始学习AcWing算法《算法竞赛进阶指南》;
上传博客方便复习。
//Wecccccccc
//2020.12.31
#include <iostream>
using namespace std;
#include <vector>struct note {int kind;int v, w;
};vector <note> kinds;
int n, v, v1, w, dp[1010], s;
int main() {cin >> n >> v;for (int i = 0; i < n; i++) {cin >> v1 >> w >> s;if (s < 0) {kinds.push_back({-1, v1, w});} else if (s == 0) {kinds.push_back({0, v1, w});} else {for (int k = 1; k <= s ; k *= 2) {s -= k;kinds.push_back({-1, v1 * k, w * k});}if ( s > 0) {kinds.push_back({-1, v1 * s, w * s});}}}for (auto x : kinds ) {if (x.kind < 0) {for (int j = v; j >= x.v; j--) {dp[j] = max(dp[j], dp[j - x.v] + x.w);}} else {for (int j = x.v; j <= v; j++) {dp[j] = max(dp[j], dp[j - x.v] + x.w);}}}cout << dp[v] << endl;return 0;
}