AcWing 4. 多重背包问题 I
原题链接
简单
作者:
ATK
,
2021-02-25 09:54:33
,
所有人可见
,
阅读 295
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int V = sc.nextInt();
int[] v = new int[N + 1];
int[] w = new int[N + 1];
int[] s = new int[N + 1];
for(int i = 1; i <= N; i++) {
v[i] = sc.nextInt();
w[i] = sc.nextInt();
s[i] = sc.nextInt();
}
int[] f = new int[V + 1];
for(int i = 1; i <= N; i++){
for(int j = V; j >= v[i]; j--){
for(int k = 1; k * v[i] <= j && k <= s[i]; k++){
f[j] = Math.max(f[j], f[j - k * v[i]] + k * w[i]);
}
}
}
System.out.println(f[V]);
}
}