![](https://img.haomeiwen.com/i1935919/8653585999ffe571.jpg)
![](https://img.haomeiwen.com/i1935919/e1ad04b0215cd6eb.jpg)
import java.util.Scanner;
/*解题思路:
* A获得人数的身高就加,B获得人数的身高就减,最后看结果是否大于0。
* 定义dp[i]为 A - B的差, 最后判断dp[n] > 0即可。*/
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();// 同事数量
int[] colls = new int[m];// 同事身高数组
for (int i = 0; i < m; ++i) {
colls[i] = sc.nextInt();
}
int score = winner(colls, 0, 1);
if (score > 0) {
System.out.println("true");
} else {
System.out.println("false");
}
sc.close();
}
public static final int winner(int[] nums, int s, int turn) {
if (s > nums.length - 1) {
return 0;
}
if (s == nums.length - 1) {
return turn * nums[s];
}
int a = turn * (nums[s]) + winner(nums, s + 1, -turn);
int b = turn * (nums[s] + nums[s + 1]) + winner(nums, s + 2, -turn);
return turn * Math.max(turn * a, turn * b);
}
}
这题直接输出“true”,测试用例60%。
网友评论