第四题 回溯 class Pdd4 { public int MinMax = Integer.MAX_VALUE; public void reset() { MinMax = Integer.MAX_VALUE; } public void helper(int[] frogs, int M, int K, int loc) { int T = frogs.length; if (M == 0) { int max = max(frogs); MinMax = Math.min(MinMax, max); return; } if (loc < 0 || loc >= T) { return; } int tmp = frogs[loc]; frogs[loc] = frogs[loc] <= K ? 0 : frogs[loc] - K; helper(frogs, M-1, K, loc+1); helper(frogs, M-1, K, loc-1); frogs[loc] = tmp; } public int max(int[] frogs, int head, int rear) { int ret = 0; for (int i=head; i <= rear; i++) { ret = Math.max(frogs[i], ret); } return ret; } public int max(int[] frogs) { int ret = 0; for (int i: frogs) { ret = Math.max(i, ret); } return ret; } }