Codeforces Round 1083 (Div. 2)
E
Simons and Dividing the Rhythm
Codeforces
2100
原题
← DF →
翻译中…

I grip my troubles within my hand, then hurl them off a thousand lands.— SHUN, ONMYWAY

翻译中…

Consider that Simons is given an array $a$ of size $m$.

翻译中…

Simons must operate on the array exactly once as follows:

翻译中…
  • First, he has to select an integer $k$ and choose $k$ pairs of integers $[l_1,r_1],[l_2,r_2],\ldots,[l_k,r_k]$, such that:
  • $l_i\le r_i$ for each $1\le i\le k$,
    • $l_1=1$, $r_k=m$, and
    • $r_i+1=l_{i+1}$ for each $i$ from $1$ to $k-1$.
  • Then, he reverses each subarray $[a_{l_i},a_{l_i+1},\ldots, a_{r_i}]$ independently. After this, the array will become $[a_{r_1},a_{r_1-1},\ldots,a_{l_1},a_{r_2},\ldots,a_{l_{k-1}},a_{r_{k}},a_{r_k-1},\ldots,a_{l_k}]$.
翻译中…

You are given an array $T$ of size $n$. Count the number of arrays $S$ such that Simons can transform $S$ to $T$, 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 8000$). The description of the test cases follows.

翻译中…

The first line contains an integer $n$ ($1\le n\le 8000$) — the length of $T$.

翻译中…

The second line contains $n$ integers $T_1,T_2,\ldots,T_n$ ($1\le T_i\le 8000$) — the elements of $T$.

翻译中…

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

翻译中…

Output

翻译中…

For each test case, output a single integer — the number of arrays $S$, modulo $998\,244\,353$.

翻译中…

Note

翻译中…

In the first test case, we can see only the following arrays can be transformed to $T$:

翻译中…
  • For $S=[2,1,1,1]$, Simons will choose $[1,3]$ and $[4,4]$. Thus, the array will become $[1,1,2,1]$, equal to $T$.
  • For $S=[1,2,1,1]$, Simons will choose $[1,4]$.
  • For $S=[1,1,2,1]$, Simons will choose $[1,2]$, $[3,3]$, and $[4,4]$.
  • For $S=[1,1,1,2]$, Simons will choose $[1,2]$ and $[3,4]$.
翻译中…

In the second test case, we can see only the following arrays can be transformed to $T$:

翻译中…
  • For $S=[1,1,3,2]$, Simons will choose $[1,1]$ and $[2,4]$.
  • For $S=[1,2,1,3]$, Simons will choose $[1,1]$, $[2,2]$, and $[3,4]$.
  • For $S=[1,2,3,1]$, Simons will choose $[1,1]$, $[2,2]$, $[3,3]$, and $[4,4]$.
  • For $S=[1,3,2,1]$, Simons will choose $[1,4]$.
  • For $S=[2,1,1,3]$, Simons will choose $[1,2]$ and $[3,4]$.
  • For $S=[2,1,3,1]$, Simons will choose $[1,2]$, $[3,3]$, and $[4,4]$.
  • For $S=[3,2,1,1]$, Simons will choose $[1,3]$ and $[4,4]$.
翻译中…

样例

Input #1
5
4
1 1 2 1
4
1 2 3 1
6
1 3 2 3 3 2
10
2 3 1 4 3 1 4 3 1 2
1
8000
Output #1
4
7
22
383
1
InputCopy OutputCopy
题目信息
题号
2205E
时间限制
2 s
内存限制
512 MB
标签
组合数学
数据结构
动态规划
并查集
数学
后缀结构
字符串

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