Ethflow Round 1 (Codeforces Round 1001, Div. 1 + Div. 2)
A
String
Codeforces
800
原题
←B →
翻译中…

You are given a string $s$ of length $n$ consisting of $\mathtt{0}$ and/or $\mathtt{1}$. In one operation, you can select a non-empty subsequence $t$ from $s$ such that any two adjacent characters in $t$ are different. Then, you flip each character of $t$ ($\mathtt{0}$ becomes $\mathtt{1}$ and $\mathtt{1}$ becomes $\mathtt{0}$). For example, if $s=\mathtt{\underline{0}0\underline{101}}$ and $t=s_1s_3s_4s_5=\mathtt{0101}$, after the operation, $s$ becomes $\mathtt{\underline{1}0\underline{010}}$.

翻译中…

Calculate the minimum number of operations required to change all characters in $s$ to $\mathtt{0}$.

翻译中…

Recall that for a string $s = s_1s_2\ldots s_n$, any string $t=s_{i_1}s_{i_2}\ldots s_{i_k}$ ($k\ge 1$) where $1\leq i_1 \lt i_2 \lt \ldots \lt i_k\leq n$ is a subsequence of $s$.

翻译中…

Input

翻译中…

The first line of input contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of input test cases.

翻译中…

The only line of each test case contains the string $s$ ($1\le |s|\le 50$), where $|s|$ represents the length of $s$.

翻译中…

Output

翻译中…

For each test case, output the minimum number of operations required to change all characters in $s$ to $\mathtt{0}$.

翻译中…

Note

翻译中…

In the first test case, you can flip $s_1$. Then $s$ becomes $\mathtt{0}$, so the answer is $1$.

翻译中…

In the fourth test case, you can perform the following three operations in order:

翻译中…
  1. Flip $s_1s_2s_3s_4s_5$. Then $s$ becomes $\mathtt{\underline{01010}}$.
  2. Flip $s_2s_3s_4$. Then $s$ becomes $\mathtt{0\underline{010}0}$.
  3. Flip $s_3$. Then $s$ becomes $\mathtt{00\underline{0}00}$.
翻译中…

It can be shown that you can not change all characters in $s$ to $\mathtt{0}$ in less than three operations, so the answer is $3$.

翻译中…

样例

Input #1
5
1
000
1001
10101
01100101011101
Output #1
1
0
2
3
8
InputCopy OutputCopy
题目信息
题号
2062A
时间限制
1 s
内存限制
512 MB
标签
构造
贪心
数学
字符串

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