没搞懂这道题,完全没思路,借鉴了讨论区大脑的dp,优化了存储。为什么会想到dp,思考之,只可意会,发现其实只与1的数量和最后一位是否为1有关。
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int[] ints = new int[n];
for(int i = 0; i < n; i++){
ints[i] = scanner.nextInt();
}
int cnt = ints[n - 1];
for(int i = ints.length-1; i >= 0; i--){
if(ints[i] == 1){
cnt += 2;
}
}
if(cnt % 2 == 1){
System.out.println("Alice");
}else{
System.out.println("Bob");
}
}
}

京公网安备 11010502036488号