AcWing 6. 多重背包问题 III
原题链接
困难
作者:
Karma
,
2021-03-13 15:58:48
,
所有人可见
,
阅读 338
import java.util.*;
class Main{
static int[] f, g, q;
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int N, V;
N = in.nextInt();
V = in.nextInt();
f = new int[V+1];
q = new int[V+1];
for(int i=0; i<N; i++){
int v, w, s;
v = in.nextInt();
w = in.nextInt();
s = in.nextInt();
g = f.clone();
for(int j=0; j<v; j++){
int hh, tt;
hh = 0; tt=-1;
for(int k=j; k<=V; k+=v){
if(tt>=hh&&k-s*v>q[hh]) hh++;
while(tt>=hh&&g[k]>g[q[tt]]+(k-q[tt])/v*w) tt--;
q[++tt] = k;
f[k] = g[q[hh]]+(k-q[hh])/v*w;
}
}
}
System.out.println(f[V]);
}
}