311339: CF1971D. Binary Cut
Description
You are given a binary string$^{\dagger}$. Please find the minimum number of pieces you need to cut it into, so that the resulting pieces can be rearranged into a sorted binary string.
Note that:
- each character must lie in exactly one of the pieces;
- the pieces must be contiguous substrings of the original string;
- you must use all the pieces in the rearrangement.
$^{\dagger}$ A binary string is a string consisting of characters $\texttt{0}$ and $\texttt{1}$. A sorted binary string is a binary string such that all characters $\texttt{0}$ come before all characters $\texttt{1}$.
InputThe first line contains a single integer $t$ ($1 \leq t \leq 500$) — the number of test cases.
The only line of each test case contains a single string $s$ ($1 \leq |s| \leq 500$) consisting of characters $\texttt{0}$ and $\texttt{1}$, where $|s|$ denotes the length of the string $s$.
OutputFor each test case, output a single integer — the minimum number of pieces needed to be able to rearrange the string into a sorted binary string.
ExampleInput6 11010 00000000 1 10 0001111 0110Output
3 1 1 2 1 2Note
The first test case is pictured in the statement. It can be proven that you can't use fewer than $3$ pieces.
In the second and third test cases, the binary string is already sorted, so only $1$ piece is needed.
In the fourth test case, you need to make a single cut between the two characters and rearrange them to make the string $\texttt{01}$.
Output
给定一个二进制字符串,请找出将其切成多少块的最小数量,以便可以将这些块重新排列成一个排序的二进制字符串。排序的二进制字符串是指所有的字符'0'都在所有的字符'1'之前。
输入数据格式:
第一行包含一个整数t(1≤t≤500)——测试用例的数量。
每个测试用例仅包含一行,有一个字符串s(1≤|s|≤500),由字符'0'和'1'组成,其中|s|表示字符串s的长度。
输出数据格式:
对于每个测试用例,输出一个整数——将字符串重新排列为排序的二进制字符串所需的最小块数。
例:
输入
```
6
11010
00000000
1
10
0001111
0110
```
输出
```
3
1
1
2
1
2
```
注意:
- 每个字符必须恰好位于一个块中;
- 块必须是原始字符串的连续子字符串;
- 必须在重新排列中使用所有的块。题目大意: 给定一个二进制字符串,请找出将其切成多少块的最小数量,以便可以将这些块重新排列成一个排序的二进制字符串。排序的二进制字符串是指所有的字符'0'都在所有的字符'1'之前。 输入数据格式: 第一行包含一个整数t(1≤t≤500)——测试用例的数量。 每个测试用例仅包含一行,有一个字符串s(1≤|s|≤500),由字符'0'和'1'组成,其中|s|表示字符串s的长度。 输出数据格式: 对于每个测试用例,输出一个整数——将字符串重新排列为排序的二进制字符串所需的最小块数。 例: 输入 ``` 6 11010 00000000 1 10 0001111 0110 ``` 输出 ``` 3 1 1 2 1 2 ``` 注意: - 每个字符必须恰好位于一个块中; - 块必须是原始字符串的连续子字符串; - 必须在重新排列中使用所有的块。