QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 256 MB Total points: 100

#12025. 排列

统计

在出题的过程中,九条可怜经常需要造一些比较长的数列。

这天,她拍脑袋想了一个可以通过长度为 $n$ 的排列构造 $O(n \times n!)$ 长度序列的方法:给出一个长度为 $n$ 的排列 $P$,设长度为 $n$ 的排列中一共有 $m$ 个字典序小于等于 $P$,它们按照字典序从小到大编号为 $P_1, \dots, P_m$,那么通过 $P$ 构造的序列 $S(P)$ 等于 $P_{1,1}, \dots, P_{1,n}, P_{2,1}, \dots, P_{m,n}$,它的长度为 $n \times m$。

举例来说,如果 $P=[2,1,3]$,那么字典序小于等于它的长度为 $3 $的排列一共有三个:$[1,2,3],[1,3,2],[2,1,3]$,因此 $S(P)=[1,2,3,1,3,2,2,1,3]$。

现在,给出一个长度为 $n$ 的排列 $P$,可怜希望你计算 $S(P)$ 的本质不同的子序列个数(可以为空)。

序列 $t$ 是 $s$ 的子序列当且仅当 $t$ 可以通过将 $s$ 删去一些字符(可以全删也可以不删)来得到。

两个序列 $t_1,t_2$ 是本质不同的当且仅当它们的长度不同或者存在某个下标对应的元素不同。

输入格式

第一行输入一个正整数 $n(1 \leq n \leq 50)$。

第二行输入一个长度为 $n$ 的排列 $P_1, \dots, P_n(1 \leq P_i \leq n)$。

输出格式

输入一行一个整数表示答案,答案可能很大,你只需要输出对 $998244353$ 取模后的值即可。

样例数据

样例 1 输入

2
2 1

样例 1 输出

11

样例 2 输入

3
3 1 2

样例 2 输出

8703

样例 3 输入

8
8 1 7 2 6 3 5 4

样例 3 输出

644319900

子任务

Subtask1(21分):$n \leq 8$。

Subtask2(47分):$P_i = n-i+1$。

Subtask3(32分):无特殊限制。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.