CF2229H.Wowee Binary String

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You find yourself with a string ss of length nn consisting of only the characters 0\texttt{0}, 1\texttt{1} and ?\texttt{?}. In other words, ss is an incomplete binary string. You will do the following operations in order:

  1. replace all ?\texttt{?} in ss with either 0\texttt{0} or 1\texttt{1}.
  2. then repeat the following any number of times (possibly none):
    • select a substring of ss with an even number of occurrences of the character 1\texttt{1} and delete it. More formally, select two integers ll, rr where 1≤l≤r≤∣s∣1 \le l \le r \le |s| and 1\texttt{1} occurs in sl,sl+1,…,srs_l,s_{l + 1},\ldots,s_r an even number of times, then replace ss with s1,…,sl−1,sr+1,…,s∣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 353998\,244\,353.

你得到一个长度为 nn 的字符串 ss,它仅由字符 0\texttt{0}、1\texttt{1} 和 ?\texttt{?} 组成。换言之,ss 是一个不完整的二进制字符串。你将按以下顺序执行如下操作:

  1. 将 ss 中所有 ?\texttt{?} 替换为 0\texttt{0} 或 1\texttt{1};
  2. 然后重复执行以下操作任意次(包括零次):
    • 选择 ss 的一个子串,该子串中字符 1\texttt{1} 出现的次数为偶数,并将其删除。更准确地说,选择两个整数 ll、rr,满足 1≤l≤r≤∣s∣1 \le l \le r \le |s|,且 1\texttt{1} 在 sl,sl+1,…,srs_l,s_{l + 1},\ldots,s_r 中出现偶数次,然后将 ss 替换为 s1,…,sl−1,sr+1,…,s∣s∣s_1,\ldots,s_{l - 1},s_{r + 1},\ldots,s_{|s|}。

求执行上述操作后能得到多少个不同的二进制字符串。由于答案可能极大,请对 998 244 353998\,244\,353 取模。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1001 \le t \le 100). The description of the test cases follows.

The first line of each testcase contains an integer nn (1≤n≤30001 \le n \le 3000) — the length of the string.

The second line of each test case contains the incomplete binary string ss.

It is guaranteed that the sum of nn over all test cases does not exceed 30003000.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1001 \le t \le 100)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤30001 \le n \le 3000)—— 字符串的长度。

每个测试用例的第二行包含不完整的二进制字符串 ss。

保证所有测试用例的 nn 值之和不超过 30003000。

输出格式

For each testcase, output the number of binary strings that can be obtained, modulo 998 244 353998\,244\,353.

对于每个测试用例,输出可得到的二进制字符串的数量,对 998 244 353998\,244\,353 取模。

输入输出样例

  • 输入#1

    7
    1
    ?
    5
    ?????
    5
    ?1001
    8
    10010001
    7
    00??10?
    7
    ?1?0?1?
    16
    0??000?00??1?1?0

    输出#1

    3
    63
    14
    18
    71
    95
    5399

说明/提示

In the first two testcases, any binary string of length no longer than nn can be made.

In the third testcase, the following strings can be made: ϵ,0,1,01,11,001,011,101,111,0101,1001,1101,01001,11001\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.

An example of how 1\texttt{1} can be made is as follows:

  • ?1001→11001\mathtt{\color{red}{?}1001} \rightarrow \mathtt{11001}
  • 11001→01\mathtt{\color{red}{110}01} \rightarrow \mathtt{01}
  • 01→1\mathtt{\color{red}{0}1} \rightarrow \mathtt{1}

在前两个测试用例中,任意长度不超过 nn 的二进制字符串均可被构造出来。

在第三个测试用例中,可被构造出的字符串包括:ϵ,0,1,01,11,001,011,101,111,0101,1001,1101,01001,11001\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 表示空字符串。

以下是一个构造字符串 1\texttt{1} 的示例:

  • ?1001→11001\mathtt{\color{red}{?}1001} \rightarrow \mathtt{11001}
  • 11001→01\mathtt{\color{red}{110}01} \rightarrow \mathtt{01}
  • 01→1\mathtt{\color{red}{0}1} \rightarrow \mathtt{1}

输入解题思路,AI测评打分。不知道怎么写?

首页