Wowee 二进制字符串AI (CI翻译)
You find yourself with a string $s$ of length $n$ consisting of only the characters $\texttt{0}$, $\texttt{1}$ and $\texttt{?}$. In other words, $s$ is an incomplete binary string. You will do the following operations in order:
你有一个长度为 $n$ 的字符串 $s$,其中只包含字符 $\texttt{0}$、$\texttt{1}$ 和 $\texttt{?}$。换句话说,$s$ 是一个不完整的二进制字符串。你需要按顺序执行以下操作:AI (CI翻译)
- replace all
$\texttt{?}$in$s$with either$\texttt{0}$or$\texttt{1}$. - then repeat the following any number of times (possibly none):
- select a substring of
$s$with an even number of occurrences of the character$\texttt{1}$and delete it. More formally, select two integers$l$,$r$where$1 \le l \le r \le |s|$and$\texttt{1}$occurs in$s_l,s_{l + 1},\ldots,s_r$an even number of times, then replace$s$with$s_1,\ldots,s_{l - 1},s_{r + 1},\ldots,s_{|s|}$
- 将
$s$中所有的$\texttt{?}$替换为$\texttt{0}$或$\texttt{1}$。 - 然后重复执行以下操作任意次(也可以一次都不执行):
- 选择一个包含偶数个字符
$\texttt{1}$的$s$的子串,并将其删除。更正式地,选择两个整数$l$、$r$,满足$1 \le l \le r \le |s|$,且$\texttt{1}$在$s_l,s_{l + 1},\ldots,s_r$中出现的次数为偶数,然后将$s$替换为$s_1,\ldots,s_{l - 1},s_{r + 1},\ldots,s_{|s|}$。
- 选择一个包含偶数个字符
Find how many different binary strings can be obtained after performing the operations. As the number could be humungous, find it modulo $998\,244\,353$.
求执行上述操作后能够得到的不同二进制字符串的数量。由于答案可能非常大,请将其对 $998\,244\,353$ 取模。AI (CI翻译)
Input
输入格式
AI (CI翻译)Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). The description of the test cases follows.
每个测试包含多个测试用例。第一行包含测试用例的数量 $t$($1 \le t \le 100$)。接下来是各个测试用例的描述。AI (CI翻译)
The first line of each testcase contains an integer $n$ ($1 \le n \le 3000$) — the length of the string.
每个测试用例的第一行包含一个整数 $n$($1 \le n \le 3000$),表示字符串的长度。AI (CI翻译)
The second line of each test case contains the incomplete binary string $s$.
每个测试用例的第二行包含不完整的二进制字符串 $s$。AI (CI翻译)
It is guaranteed that the sum of $n$ over all test cases does not exceed $3000$.
保证所有测试用例的 $n$ 之和不超过 $3000$。AI (CI翻译)
Output
输出格式
AI (CI翻译)For each testcase, output the number of binary strings that can be obtained, modulo $998\,244\,353$.
对于每个测试用例,输出能够得到的二进制字符串的数量,并将结果对 $998\,244\,353$ 取模。AI (CI翻译)
Note
说明
AI (CI翻译)In the first two testcases, any binary string of length no longer than $n$ can be made.
在前两个测试用例中,长度不超过 $n$ 的任意二进制字符串都可以得到。AI (CI翻译)
In the third testcase, the following strings can be made: $\epsilon, \mathtt{0}, \mathtt{1}, \mathtt{01}, \mathtt{11}, \mathtt{001}, \mathtt{011}, \mathtt{101}, \mathtt{111}, \mathtt{0101}, \mathtt{1001}, \mathtt{1101}, \mathtt{01001}, \mathtt{11001}$, where $\epsilon$ represents the empty string.
在第三个测试用例中,可以得到以下字符串:$\epsilon, \mathtt{0}, \mathtt{1}, \mathtt{01}, \mathtt{11}, \mathtt{001}, \mathtt{011}, \mathtt{101}, \mathtt{111}, \mathtt{0101}, \mathtt{1001}, \mathtt{1101}, \mathtt{01001}, \mathtt{11001}$,其中 $\epsilon$ 表示空字符串。AI (CI翻译)
An example of how $\texttt{1}$ can be made is as follows:
以下是得到 $\texttt{1}$ 的一种方法:AI (CI翻译)
$\mathtt{\color{red}{?}1001} \rightarrow \mathtt{11001}$$\mathtt{\color{red}{110}01} \rightarrow \mathtt{01}$$\mathtt{\color{red}{0}1} \rightarrow \mathtt{1}$
$\mathtt{\color{red}{?}1001} \rightarrow \mathtt{11001}$$\mathtt{\color{red}{110}01} \rightarrow \mathtt{01}$$\mathtt{\color{red}{0}1} \rightarrow \mathtt{1}$
样例
7
1
?
5
?????
5
?1001
8
10010001
7
00??10?
7
?1?0?1?
16
0??000?00??1?1?0
3
63
14
18
71
95
5399
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。