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 人评分
A+B for Input-Output Practice (C++代码)浏览:605 |
【绝对值排序】 (C语言代码)浏览:820 |
C语言程序设计教程(第三版)课后习题9.2 (C语言代码)浏览:556 |
1124题解浏览:592 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:511 |
计算质因子 (C语言代码)浏览:697 |
陶陶摘苹果2 (C语言代码)浏览:595 |
简单的a+b (C语言代码)浏览:462 |
陶陶摘苹果2 (C++代码)浏览:537 |
C语言程序设计教程(第三版)课后习题5.5 (C语言代码)浏览:525 |