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 人评分
C语言程序设计教程(第三版)课后习题10.5 (C语言代码)浏览:717 |
时间转换 (Java代码)浏览:572 |
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:544 |
人见人爱A+B (C语言代码)浏览:625 |
C语言程序设计教程(第三版)课后习题9.2 (C语言代码)浏览:556 |
回文数字 (C语言代码)浏览:2509 |
P1000 (C语言代码)浏览:868 |
核桃的数量 (C语言代码)浏览:668 |
A+B for Input-Output Practice (C语言代码)浏览:458 |
核桃的数量 (C语言代码)浏览:870 |