import java.util.Scanner; public class 简化型背包 { static int V, W; static int[] p = new int[6]; static int[] v = new int[6]; static int[] w = new int[6]; public static void main(String[] args) { Scanner sc = new Scanner(System.in); V = sc.nextInt();// 最大体积 W = sc.nextInt();// 最大重量 for (int i = 1; i < 6; i++) { p[i] = sc.nextInt(); v[i] = sc.nextInt(); w[i] = sc.nextInt(); } dfs(0, 0, 0, 0); System.out.println(Max); } static int Max = Integer.MIN_VALUE; public static void dfs(int MaxV, int MaxW, int i, int P) { MaxV += v[i]; MaxW += w[i]; P += p[i]; Max = Math.max(P, Max); if (MaxV == V || MaxW == W)return; for (int j = i + 1; j < 6; j++) { if (MaxV + v[j] <= V && MaxW + w[j] <= W) { dfs(MaxV, MaxV, j, P); } } } }
0.0分
2 人评分