也是二进制拆分 可能更简单一些
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 25000;
int f[N];
//int v[20001] = { 0 }, w[20001] = { 0 }, s[1001] = { 0 };
int main(void) {
int n, m;
scanf("%d %d", &n, &m);
memset(f, 0, sizeof(f));
int v, w, s;
for (int i = 0; i < n; i++) {
scanf("%d %d %d", &v, &w, &s);
int num = min(s, m / v); //节省1
for (int k = 1; num > 0; k <<= 1) { //节省2 <<=是左移操作
if (k > num)
k = num; //注意这里和for循环的结束条件
num -= k;
for (int j = m; j >= v * k; j--) {
f[j] = max(f[j], f[j - v * k] + w * k);
}
}
}
printf("%d\n", f[m]);
return 0;
}
老哥,你这也太省了0.0