308477: CF1527B1. Palindrome Game (easy version)
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Palindrome Game (easy version)
题意翻译
给定一个$01$回文串$s$,可以进行如下操作 - 修改一个$0$为$1$,消耗一点能量 - 翻转这个串,条件是这个串**当前是不回文的**,且**上一个人没有翻转** $ALICE$和$BOB$轮流操作,**均采用最优策略**,$ALICE$先手,当这个串全部为$1$时**花费能量少者获胜**,输出获胜者名字,一行一个,平局输出$DRAW$ ### 输入 多测,第一行测试组数$t$ 接下来$2t$行,每$2$行为一组,包含回文串长度和回文串题目描述
The only difference between the easy and hard versions is that the given string $ s $ in the easy version is initially a palindrome, this condition is not always true for the hard version. A palindrome is a string that reads the same left to right and right to left. For example, "101101" is a palindrome, while "0101" is not. Alice and Bob are playing a game on a string $ s $ (which is initially a palindrome in this version) of length $ n $ consisting of the characters '0' and '1'. Both players take alternate turns with Alice going first. In each turn, the player can perform one of the following operations: 1. Choose any $ i $ ( $ 1 \le i \le n $ ), where $ s[i] = $ '0' and change $ s[i] $ to '1'. Pay 1 dollar. 2. Reverse the whole string, pay 0 dollars. This operation is only allowed if the string is currently not a palindrome, and the last operation was not reverse. That is, if Alice reverses the string, then Bob can't reverse in the next move, and vice versa. Reversing a string means reordering its letters from the last to the first. For example, "01001" becomes "10010" after reversing. The game ends when every character of string becomes '1'. The player who spends minimum dollars till this point wins the game and it is a draw if both spend equal dollars. If both players play optimally, output whether Alice wins, Bob wins, or if it is a draw.输入输出格式
输入格式
The first line contains a single integer $ t $ ( $ 1 \le t \le 10^3 $ ). Then $ t $ test cases follow. The first line of each test case contains a single integer $ n $ ( $ 1 \le n \le 10^3 $ ). The second line of each test case contains the string $ s $ of length $ n $ , consisting of the characters '0' and '1'. It is guaranteed that the string $ s $ is a palindrome and contains at least one '0'. Note that there is no limit on the sum of $ n $ over test cases.
输出格式
For each test case print a single word in a new line: - "ALICE", if Alice will win the game, - "BOB", if Bob will win the game, - "DRAW", if the game ends in a draw.
输入输出样例
输入样例 #1
2
4
1001
1
0
输出样例 #1
BOB
BOB