

import java.util.Scanner;
/*解題思路:
* A獲得人數(shù)的身高就加,B獲得人數(shù)的身高就減,最后看結(jié)果是否大于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();// 同事數(shù)量
int[] colls = new int[m];// 同事身高數(shù)組
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%。