privatestaticvoidT1() { Scannerin=newScanner(System.in); intlen= in.nextInt(); // if (len == 2) { // System.out.println(in.nextInt() * in.nextInt()); // } // else if (len == 3) { // int one = in.nextInt(); // int two = in.nextInt(); // int three = in.nextInt(); // int a = one * two; // int b = two * three; // int c = one * three; // System.out.println(Math.max(a, Math.max(b, c))); // } // else if (len == 4) { // int one = in.nextInt(); // int two = in.nextInt(); // int three = in.nextInt(); // int four = in.nextInt(); // int a = one * two; // int end = three * four; //// ====== //// int b = two * three; // int c = one * three; // int d = two * four; // System.out.println(Math.max(a, Math.max(end, Math.max(c, d)))); // }
// else { long[] nums = newlong[len]; for (inti=0; i < len; i++) { nums[i] = in.nextLong(); } longmax=0; for (inti=0; i < len - 1; i++) { if (i + 2 < len) { max = Math.max(max, nums[i] * nums[i + 2]); } max = Math.max(max, nums[i] * nums[i + 1]); } System.out.println(max); // } }
米小游买商品
商店里有 n个商品,分别编号为 1~n ,每个商品都有一个价值 vali和体积 wi,米小游有一个有一个 m 容量的背包,他能够装得下任意多个体积之和不超过 m 的商品。
米小游认为有些东西一起购买会带来灾难,比如可莉的角色立牌和蹦蹦炸弹的小手办,所以他设定了 k组互斥关系,每组关系给定两个数字 a,b,表示编号为 a 的商品和编号为 b的商品不能同时购买。
publicclassMain { privatestaticint n, m, k; privatestaticint[][] stocks; // {weight, value} privatestatic Set<Integer>[] mutexes; privatestaticintres=0;
privatestaticbooleancheck(int i, Set<Integer> vst) { for (int v : vst) { if (mutexes[v].contains(i)) { returnfalse; } } returntrue; }
privatestaticvoidbacktrace(int i, int curValue, int curWeight, Set<Integer> vst) { if (i >= n) { res = Math.max(res, curValue); return; } backtrace(i + 1, curValue, curWeight, vst);