Codeforces Round 1005 (Div. 2)
A
Brogramming Contest
Codeforces
800
原题
←B →
翻译中…

One day after waking up, your friend challenged you to a brogramming contest. In a brogramming contest, you are given a binary string$^{\text{∗}}$ $s$ of length $n$ and an initially empty binary string $t$. During a brogramming contest, you can make either of the following moves any number of times:

翻译中…
  • remove some suffix$^{\text{†}}$ from $s$ and place it at the end of $t$, or
  • remove some suffix from $t$ and place it at the end of $s$.
翻译中…

To win the brogramming contest, you must make the

翻译中…

minimum

翻译中…

number of moves required to make $s$ contain only the character $\texttt{0}$ and $t$ contain only the character $\texttt{1}$. Find the minimum number of moves required.

翻译中…

$^{\text{∗}}$A binary string is a string consisting of characters $\texttt{0}$ and $\texttt{1}$.$^{\text{†}}$A string $a$ is a suffix of a string $b$ if $a$ can be obtained from deletion of several (possibly, zero or all) elements from the beginning of $b$.

翻译中…

Input

翻译中…

The first line contains an integer $t$ ($1 \le t \le 100$) — the number of test cases.

翻译中…

The first line of each test case is an integer $n$ ($1 \le n \le 1000$) — the length of the string $s$.

翻译中…

The second line of each test case contains the binary string $s$.

翻译中…

The sum of $n$ across all test cases does not exceed $1000$.

翻译中…

Output

翻译中…

For each testcase, output the minimum number of moves required.

翻译中…

Note

翻译中…

An optimal solution to the first test case is as follows:

翻译中…
  • $s = \texttt{00}\color{red}{\texttt{110}}$, $t =$ empty string.
  • $s = \texttt{00}$, $t = \texttt{11}\color{red}{\texttt{0}}$.
  • $s = \texttt{000}$, $t = \texttt{11}$.
翻译中…

It can be proven that there is no solution using less than $2$ moves.

翻译中…

In the second test case, you have to move the whole string from $s$ to $t$ in one move.

翻译中…

In the fourth test case, you don't have to do any moves.

翻译中…

样例

Input #1
5
5
00110
4
1111
3
001
5
00000
3
101
Output #1
2
1
1
0
3
InputCopy OutputCopy
题目信息
题号
2064A
时间限制
1 s
内存限制
256 MB
标签
贪心
字符串

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。