CF2205E.Simons and Dividing the Rhythm
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 [l1,r1],[l2,r2],…,[lk,rk], such that:
- li≤ri for each 1≤i≤k,
- l1=1, rk=m, and
- ri+1=li+1 for each i from 1 to k−1.
- Then, he reverses each subarray [ali,ali+1,…,ari] independently. After this, the array will become [ar1,ar1−1,…,al1,ar2,…,alk−1,ark,ark−1,…,alk].
You are given an array T of size n. Count the number of arrays S such that Simons can transform S to T, modulo 998244353.
我将烦恼紧握于掌中,然后将其掷向千里之外。
—— SHUN,《ONMYWAY》Spotify 链接
考虑 Simons 被给定一个长度为 m 的数组 a。
Simons 必须对这个数组恰好执行一次如下操作:
- 首先,他需选定一个整数 k,并选择 k 对整数 [l1,r1],[l2,r2],…,[lk,rk],满足:
- 对每个 1≤i≤k,有 li≤ri;
- l1=1,rk=m;
- 对每个 i=1 到 k−1,有 ri+1=li+1。
- 然后,他独立地将每个子数组 [ali,ali+1,…,ari] 进行翻转。操作完成后,数组变为
[ar1,ar1−1,…,al1,ar2,…,alk−1,ark,ark−1,…,alk]。
现给定一个长度为 n 的数组 T。请计算满足“Simons 可将数组 S 经上述操作变换为 T”的数组 S 的个数,结果对 998244353 取模。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤8000). The description of the test cases follows.
The first line contains an integer n (1≤n≤8000) — the length of T.
The second line contains n integers T1,T2,…,Tn (1≤Ti≤8000) — the elements of T.
It is guaranteed that the sum of n over all test cases does not exceed 8000.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤8000)。随后是各测试用例的描述。
第一行包含一个整数 n(1≤n≤8000)——即序列 T 的长度。
第二行包含 n 个整数 T1,T2,…,Tn(1≤Ti≤8000)——即 T 的各个元素。
保证所有测试用例的 n 值之和不超过 8000。
输出格式
For each test case, output a single integer — the number of arrays S, modulo 998244353.
对于每个测试用例,输出一个整数——满足条件的数组 S 的个数,对 998244353 取模。
输入输出样例
输入#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
输出#1
4 7 22 383 1
说明/提示
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].
在第一个测试用例中,我们只能看到以下数组可以被变换为 T:
- 对于 S=[2,1,1,1],Simon 将选择区间 [1,3] 和 [4,4]。于是,该数组将变为 [1,1,2,1],与 T 相等。
- 对于 S=[1,2,1,1],Simon 将选择区间 [1,4]。
- 对于 S=[1,1,2,1],Simon 将选择区间 [1,2]、[3,3] 和 [4,4]。
- 对于 S=[1,1,1,2],Simon 将选择区间 [1,2] 和 [3,4]。
在第二个测试用例中,我们只能看到以下数组可以被变换为 T:
- 对于 S=[1,1,3,2],Simon 将选择区间 [1,1] 和 [2,4]。
- 对于 S=[1,2,1,3],Simon 将选择区间 [1,1]、[2,2] 和 [3,4]。
- 对于 S=[1,2,3,1],Simon 将选择区间 [1,1]、[2,2]、[3,3] 和 [4,4]。
- 对于 S=[1,3,2,1],Simon 将选择区间 [1,4]。
- 对于 S=[2,1,1,3],Simon 将选择区间 [1,2] 和 [3,4]。
- 对于 S=[2,1,3,1],Simon 将选择区间 [1,2]、[3,3] 和 [4,4]。
- 对于 S=[3,2,1,1],Simon 将选择区间 [1,3] 和 [4,4]。
输入解题思路,AI测评打分。不知道怎么写?