CF1767C.Count Binary Strings

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given an integer nn . You have to calculate the number of binary (consisting of characters 0 and/or 1) strings ss meeting the following constraints.

For every pair of integers (i,j)(i, j) such that 1ijn1 \le i \le j \le n , an integer ai,ja_{i,j} is given. It imposes the following constraint on the string sisi+1si+2sjs_i s_{i+1} s_{i+2} \dots s_j :

  • if ai,j=1a_{i,j} = 1 , all characters in sisi+1si+2sjs_i s_{i+1} s_{i+2} \dots s_j should be the same;
  • if ai,j=2a_{i,j} = 2 , there should be at least two different characters in sisi+1si+2sjs_i s_{i+1} s_{i+2} \dots s_j ;
  • if ai,j=0a_{i,j} = 0 , there are no additional constraints on the string sisi+1si+2sjs_i s_{i+1} s_{i+2} \dots s_j .

Count the number of binary strings ss of length nn meeting the aforementioned constraints. Since the answer can be large, print it modulo 998244353998244353 .

输入格式

The first line contains one integer nn ( 2n1002 \le n \le 100 ).

Then nn lines follow. The ii -th of them contains ni+1n-i+1 integers ai,i,ai,i+1,ai,i+2,,ai,na_{i,i}, a_{i,i+1}, a_{i,i+2}, \dots, a_{i,n} ( 0ai,j20 \le a_{i,j} \le 2 ).

输出格式

Print one integer — the number of strings meeting the constraints, taken modulo 998244353998244353 .

输入输出样例

  • 输入#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.

首页