CF1767C.Count Binary Strings
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an integer n. You have to calculate the number of binary (consisting of characters 0 and/or 1) strings s meeting the following constraints.
For every pair of integers (i,j) such that 1≤i≤j≤n, an integer ai,j is given. It imposes the following constraint on the string sisi+1si+2…sj:
- if ai,j=1, all characters in sisi+1si+2…sj should be the same;
- if ai,j=2, there should be at least two different characters in sisi+1si+2…sj;
- if ai,j=0, there are no additional constraints on the string sisi+1si+2…sj.
Count the number of binary strings s of length n meeting the aforementioned constraints. Since the answer can be large, print it modulo 998244353.
给你一个整数 n。你需要计算满足以下约束条件的二进制字符串(仅由字符 0 和/或 1 组成)s 的数量。
对每一对满足 1≤i≤j≤n 的整数 (i,j),给定一个整数 ai,j。它对子串 sisi+1si+2…sj 施加如下约束:
- 若 ai,j=1,则 sisi+1si+2…sj 中所有字符必须相同;
- 若 ai,j=2,则 sisi+1si+2…sj 中至少包含两个不同的字符;
- 若 ai,j=0,则对子串 sisi+1si+2…sj 不施加额外约束。
计算长度为 n 且满足上述所有约束条件的二进制字符串 s 的数量。由于答案可能很大,请输出其对 998244353 取模的结果。
输入格式
The first line contains one integer n (2≤n≤100).
Then n lines follow. The i-th of them contains n−i+1 integers ai,i,ai,i+1,ai,i+2,…,ai,n (0≤ai,j≤2).
第一行包含一个整数 n(2≤n≤100)。
接下来是 n 行。其中第 i 行包含 n−i+1 个整数 ai,i,ai,i+1,ai,i+2,…,ai,n(0≤ai,j≤2)。
输出格式
Print one integer — the number of strings meeting the constraints, taken modulo 998244353.
输出一个整数——满足约束条件的字符串数量,对 998244353 取模。
输入输出样例
输入#1
3 1 0 2 1 0 1
输出#1
6
输入#2
3 1 1 2 1 0 1
输出#2
2
输入#3
3 1 2 1 1 0 1
输出#3
0
输入#4
3 2 0 2 0 1 1
输出#4
0
说明/提示
In the first example, the strings meeting the constraints are 001, 010, 011, 100, 101, 110.
In the second example, the strings meeting the constraints are 001, 110.
在第一个例子中,满足约束条件的字符串有 001、010、011、100、101、110。
在第二个例子中,满足约束条件的字符串有 001、110。
输入解题思路,AI测评打分。不知道怎么写?