CF2229H.Wowee Binary String
NOI/NOI+/CTSC
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You find yourself with a string s of length n consisting of only the characters 0, 1 and ?. In other words, s is an incomplete binary string. You will do the following operations in order:
- replace all ? in s with either 0 or 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 1 and delete it. More formally, select two integers l, r where 1≤l≤r≤∣s∣ and 1 occurs in sl,sl+1,…,sr an even number of times, then replace s with s1,…,sl−1,sr+1,…,s∣s∣
Find how many different binary strings can be obtained after performing the operations. As the number could be humungous, find it modulo 998244353.
你得到一个长度为 n 的字符串 s,它仅由字符 0、1 和 ? 组成。换言之,s 是一个不完整的二进制字符串。你将按以下顺序执行如下操作:
- 将 s 中所有 ? 替换为 0 或 1;
- 然后重复执行以下操作任意次(包括零次):
- 选择 s 的一个子串,该子串中字符 1 出现的次数为偶数,并将其删除。更准确地说,选择两个整数 l、r,满足 1≤l≤r≤∣s∣,且 1 在 sl,sl+1,…,sr 中出现偶数次,然后将 s 替换为 s1,…,sl−1,sr+1,…,s∣s∣。
求执行上述操作后能得到多少个不同的二进制字符串。由于答案可能极大,请对 998244353 取模。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤100). The description of the test cases follows.
The first line of each testcase contains an integer n (1≤n≤3000) — the length of the string.
The second line of each test case contains the incomplete binary string s.
It is guaranteed that the sum of n over all test cases does not exceed 3000.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤100)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤3000)—— 字符串的长度。
每个测试用例的第二行包含不完整的二进制字符串 s。
保证所有测试用例的 n 值之和不超过 3000。
输出格式
For each testcase, output the number of binary strings that can be obtained, modulo 998244353.
对于每个测试用例,输出可得到的二进制字符串的数量,对 998244353 取模。
输入输出样例
输入#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 n 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, where ϵ represents the empty string.
An example of how 1 can be made is as follows:
- ?1001→11001
- 11001→01
- 01→1
在前两个测试用例中,任意长度不超过 n 的二进制字符串均可被构造出来。
在第三个测试用例中,可被构造出的字符串包括:ϵ,0,1,01,11,001,011,101,111,0101,1001,1101,01001,11001,其中 ϵ 表示空字符串。
以下是一个构造字符串 1 的示例:
- ?1001→11001
- 11001→01
- 01→1
输入解题思路,AI测评打分。不知道怎么写?