import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int M = sc.nextInt(); int[] W = new int[N + 1];//重量 int[] V = new int[N + 1];//价值 int[] K = new int[N + 1];//数量 for (int i = 1; i <= N; i++) { W[i] = sc.nextInt(); V[i] = sc.nextInt(); K[i] = sc.nextInt(); } int[] dp = new int[M + 1];//滚动数组 for (int j = 1; j <= N; j++) { for (int i = M; i >= 1; i--) { // W[j] * k <= i:W[j]当前物品的重量*物品数量K小于等于当前背包的容量i // k <= K[j]物品数量k小于等于当前物品j的个数 for (int k = 1; W[j] * k <= i && k <= K[j]; k++) { dp[i] = Math.max(dp[i], dp[i - W[j] * k] + k * V[j]); } } } System.out.println( dp[M]); } }
0.0分
9 人评分