Codeforces Round 1086 (Div. 2)
E
Counting Cute Arrays
Codeforces
2700
原题
← D2→
翻译中…

Let $[A_1, A_2, \ldots, A_n]$ be an array of $n$ positive integers. Define array $f(A)$ as followed:

翻译中…

For each integer $i$ from $1$ to $n$:

翻译中…
  • If there exists integer $j$ such that $j \lt i$ and $A_j \lt A_i$, $f(A)_i=\max\limits_{j \lt i,A_j \lt A_i} j$. That is, $f(A)_i$ is the index of the rightmost element before $i$ whose value is strictly smaller than $A_i$.
  • Otherwise $f(A)_i=0$.
翻译中…

We call the array $[P_1,P_2,\ldots,P_n]$ of non-negative integers a cute array if there exists an array $A$ such that $f(A)=P$.

翻译中…

Given a length $n$ array $X$ in which $-1\le X_i\le n$ holds for all $i$ from $1$ to $n$. Count the numbers of cute arrays $X'$ formed by replacing the $-1$s in $X$ with integers from $0$ to $n$. As the number can be very large, print it modulo $998\,244\,353$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^3$). The description of the test cases follows.

翻译中…

The first line of each test cases contain an integer $n$ ($1\le n\le5000$) denoting the length of $X$.

翻译中…

The second line contain $n$ integers $X_1,X_2,\ldots,X_n$ ($-1\le X_i\le n$).

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $5000$.

翻译中…

Output

翻译中…

For each test cases, output a single integer denoting the number of arrays $X'$ such that $X'$ is a cute array, modulo $998\,244\,353$.

翻译中…

Note

翻译中…

For the first test case, only $[0,0,0]$ and $[0,0,2]$ are cute arrays among all possible $X'$. $[0,0,0]$ is a good cute array because $f([1,1,1])=[0,0,0]$, and $[0,0,2]$ is a good array because $f([1,1,2])=[0,0,2]$.

翻译中…

For the second test case, only $[0,1,1,0]$, $[0,1,1,1]$ and $[0,1,1,3]$ are cute arrays among all possible $X'$.

翻译中…

样例

Input #1
6
3
-1 0 -1
4
-1 -1 1 -1
5
-1 -1 -1 -1 -1
4
-1 0 2 3
4
1 1 2 3
4
0 0 0 1
Output #1
2
3
42
1
0
0
InputCopy OutputCopy
题目信息
题号
2208E
时间限制
2 s
内存限制
512 MB
标签
组合数学
动态规划

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。