#CF1107C. RemovevomeR 移除一些 R
RemovevomeR 移除一些 R
当前没有测试数据。
CF测试跳转:https://codeforces.com/contest/2241/problem/C
You are given a binary string consisting only of the characters and .
In one operation, you can do the following:
- Choose a substring of that is a palindrome of length at least .
- Delete exactly one character from this chosen substring.
The remaining parts of the string are then concatenated to form the new string .
Find the minimum possible length of the string that can be achieved after applying this operation any number of times (possibly zero).
A string is a substring of a string if can be obtained from by the deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.
A string of length is said to be palindrome if for all .
Input
The first line contains a single integer () — the number of test cases. Description of each test case follows.
The first line of each test case contains a single integer () — the length of the binary string .
The second line of each test case contains a binary string of length . It is guaranteed that each character of is either or .
Output
For each test case, print the minimum possible length of the string that can be achieved after applying the operation any number of times.
Example
4
4
0000
3
110
6
110011
6
101100
1
2
1
1
Note
In the first test case, the initial string is . We can perform the following sequence of operations:
- Choose the palindromic substring . Delete one . The string becomes .
- Choose the palindromic substring . Delete one . The string becomes .
- Choose the palindromic substring . Delete one . The string becomes .
The string contains no palindromic substrings of length at least , so no further operations can be performed. The minimum possible length is .
In the second test case, the initial string is .
- Choose the palindromic substring . Delete one . The string becomes .
The string contains no palindromic substrings of length at least , so no further operations can be performed. The minimum possible length is .