AcWing 4. 多重背包问题 I
原题链接
简单
import java.util.Scanner;
import java.lang.Math;
public class Main{
static final int N =110;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int[] v = new int[N];
int[] w = new int[N];
int[] s = new int[N];
for(int i=1;i<=n;i++){
v[i] = sc.nextInt();
w[i] = sc.nextInt();
s[i] = sc.nextInt();
}
int[][] dp = new int[N][N];
for(int i=1;i<=n;i++){
for(int j=0;j<=m;j++){
for(int k=0;k<=s[i] && k*v[i]<=j;k++){
dp[i][j] = Math.max(dp[i][j],dp[i-1][j-k*v[i]]+k*w[i]);
}
}
}
System.out.println(dp[n][m]);
}
}