You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
793 B

#include <bits/stdc++.h>
using namespace std;
const int N = 1010;
const int M = 20010;
int n, m;
int v[N], w[N], s[N];
int f[N][M];
int q[M];
//多重背包之单调队列优化
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> v[i] >> w[i] >> s[i];
for (int i = 1; i <= n; i++)
for (int r = 0; r < v[i]; r++) {
int hh = 0, tt = -1;
for (int j = r; j <= m; j += v[i]) {
while (hh <= tt && j - q[hh] > s[i] * v[i]) hh++;
while (hh <= tt && f[i - 1][q[tt]] + (j - q[tt]) / v[i] * w[i] <= f[i - 1][j]) tt--;
q[++tt] = j;
f[i][j] = f[i - 1][q[hh]] + (j - q[hh]) / v[i] * w[i];
}
}
printf("%d", f[n][m]);
return 0;
}