CF2247F.Paths on a Grid
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a grid a of size n×m. The rows are numbered from 1 to n from top to bottom, and the columns are numbered from 1 to m from left to right. Each cell of the grid is either blocked or free. Cells (1,1) and (n,m) are free.
A set S of cells of a, which may include blocked cells, is called good if the following conditions hold:
- S is non-empty;
- for every cell (i,j) belonging to S, every path from (1,1) to (n,m) that passes only through free cells, moves one cell down or one cell right at each step, and passes through (i,j) also passes through all other cells of S.
Count the number of good sets of cells of a modulo 998244353.
给你一个大小为 n×m 的网格 a。行从上到下编号为 1 到 n,列从左到右编号为 1 到 m。网格中的每个单元格要么被阻塞,要么是空闲的。单元格 (1,1) 和 (n,m) 均为空闲。
一个可能包含阻塞单元格的单元格集合 S 被称为好集合,当且仅当满足以下条件:
- S 非空;
- 对于每个属于 S 的单元格 (i,j),任意一条从 (1,1) 到 (n,m) 的路径(该路径仅经过空闲单元格,每一步只能向下或向右移动一格),只要经过 (i,j),则必然也经过 S 中所有其他单元格。
求网格 a 中好集合的个数,对 998244353 取模。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains two integers n and m (1≤n⋅m≤106).
The i-th of the following n lines contains a string ai,1ai,2…ai,m (ai,j∈0,1) — the i-th row of the grid. If ai,j=1, then cell (i,j) is free; otherwise, it is blocked. It is guaranteed that a1,1=an,m=1.
It is guaranteed that the sum of n⋅m over all test cases does not exceed 106.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 m(1≤n⋅m≤106)。
接下来的 n 行中,第 i 行包含一个字符串 ai,1ai,2…ai,m(其中 ai,j∈{0,1}),表示网格的第 i 行。若 ai,j=1,则单元格 (i,j) 是空闲的;否则该单元格被阻塞。保证 a1,1=an,m=1。
保证所有测试用例中 n⋅m 的总和不超过 106。
输出格式
For each test case, output a single integer — the answer to the problem modulo 998244353.
对于每个测试用例,输出一个整数——问题答案对 998244353 取模的结果。
输入输出样例
输入#1
6 1 1 1 2 2 11 11 2 2 10 01 2 2 11 01 4 4 1011 1101 0111 1111 1 32 10010110010001010110011111010011
输出#1
1 5 15 8 162 301989883
说明/提示
In the first example, the only non-empty set of cells is (1,1), and it is good. Therefore, the answer is 1.
In the third example, there is no path from (1,1) to (2,2) that passes only through free cells. Therefore, every non-empty set of cells is good, so the answer is 24−1=15.
In the fifth example, the set (2,2),(3,2) is good because every path from (1,1) to (4,4) that passes only through free cells and passes through either of these cells also passes through the other. On the other hand, the set (3,3),(4,3) is not good: the path (1,1)→(2,1)→(2,2)→(3,2)→(3,3)→(3,4)→(4,4) passes through (3,3) but does not pass through (4,3). It can be shown that the total number of good sets is 162.
在第一个例子中,唯一的非空单元格集合是 {(1,1)},且它是“好”的。因此答案为 1。
在第三个例子中,不存在一条从 (1,1) 到 (2,2) 的、仅经过空闲单元格的路径。因此,每个非空单元格集合都是“好”的,故答案为 24−1=15。
在第五个例子中,集合 {(2,2),(3,2)} 是“好”的,因为每条从 (1,1) 到 (4,4) 的、仅经过空闲单元格且经过其中任一单元格的路径,也必然经过另一个单元格。另一方面,集合 {(3,3),(4,3)} 不是“好”的:路径 (1,1)→(2,1)→(2,2)→(3,2)→(3,3)→(3,4)→(4,4) 经过了 (3,3),但未经过 (4,3)。可以证明,“好”集合的总数为 162。
输入解题思路,AI测评打分。不知道怎么写?