Yet Another Path Counting
1 Sec 128 MB | Markdown 公开数据 显示标签
困难 (*2400) 动态规划 组合数学 贪心
3 | 6 |
通过 | 提交 |
题目描述
We have a grid of squares with $N$ rows arranged vertically and $N$ columns arranged horizontally. The square at the $i$-th row from the top and $j$-th column from the left has an integer label $a_{i,j}$.
Consider paths obtained by starting on one of the squares and going right or down to an adjacent square zero or more times. Find the number, modulo $998244353$, of such paths that start and end on squares with the same label.
Two paths are distinguished when they visit different sets of squares (including the starting and ending squares).
输入格式
Input is given from Standard Input in the following format:
>$N$\
>$a_{1,1}$ $\cdots$ $a_{1,N}$\
>$\vdots$\
>$a_{N,1}$ $\cdots$ $a_{N,N}$
#### Constraints
- $1\le N\le 400$
- $1\le a_{i,j}\le N^2$
- All values in input are integers.
输出格式
Print the answer.
样例输入 #1
2 1 3 3 1
样例输出 #1
6
提示
The following six paths satisfy the requirements. ($(i,j)$ denotes the square at the $i$-th row from the top and $j$-th column from the left. Each path is represented as a sequence of squares it visits.)
- $(1,1)$
- $(1,1) \rightarrow (1,2) \rightarrow (2,2)$
- $(1,1) \rightarrow (2,1) \rightarrow (2,2)$
- $(1,2)$
- $(2,1)$
- $(2,2)$
来源
AtCoder [ABC259Ex]