CF1767C.Count Binary Strings
普及/提高-
通过率:0%
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 .
输入格式
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 ).
输出格式
Print one integer — the number of strings meeting the constraints, taken modulo 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.