大和証券プログラミングコンテスト2022 Spring (AtCoder Regular Contest 138)
F
KD Tree
AtCoder
⌀ 3882
原题
← E→
翻译中…

Problem Statement

翻译中…

There are $N$ points in a plane, the $i$-th ($1 \leq i \leq N$) of which is $(i,P_i)$. Here, $(P_1,P_2,\cdots,P_N)$ is a permutation of $(1,2,\cdots,N)$.

翻译中…

You can arrange a non-empty set $s$ of points, which is a recursive operation defined as follows.

翻译中…
  • If $s$ contains exactly one point, arranging it creates a sequence composed of just that point.
  • If $s$ contains two or more points, arranging it creates a sequence composed of those points by doing one of the following two operations.
  • Choose any integer $x$ and divide $s$ into two: the set $a$ of points whose $X$-coordinates are less than $x$ and the set $b$ of the other points. Here, neither $a$ nor $b$ should be empty. Create a sequence by concatenating the sequence obtained by arranging $a$ and the sequence obtained by arranging $b$ in this order.
    • Choose any integer $y$ and divide $s$ into two: the set $a$ of points whose $Y$-coordinates are less than $y$ and the set $b$ of the other points. Here, neither $a$ nor $b$ should be empty. Create a sequence by concatenating the sequence obtained by arranging $a$ and the sequence obtained by arranging $b$ in this order.
翻译中…

Find the number, modulo $(10^9+7)$, of sequences that can be obtained by arranging the set of points $\{(1,P_1),(2,P_2),\cdots,(N,P_N)\}$.

翻译中…

Constraints

翻译中…
  • $1 \leq N \leq 30$
  • $(P_1,P_2,\cdots,P_N)$ is a permutation of $(1,2,\cdots,N)$.
  • All values in input are integers.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
P_1 P_2 \cdots P_N

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
3
3 1 2
Output #1
3
The following three sequences can be obtained. - $((1,3),(2,1),(3,2))$ - $((2,1),(3,2),(1,3))$ - $((2,1),(1,3),(3,2))$ For example, the sequence $((2,1),(1,3),(3,2))$ can be obtained as follows. - Arrange the set $\{(1,3),(2,1),(3,2)\}$ by dividing it to the set of points whose $Y$-coordinates are less than $2$ ($=\{(2,1)\}$) and the set of the other points ($=\{(1,3),(3,2)\}$). - Arrange the set $\{(2,1)\}$ to obtain the sequence $((2,1))$. - Arrange the set $\{(1,3),(3,2)\}$ by dividing it to the set of points whose $X$-coordinates are less than $3$ and the set of the other points. - Arrange the set $\{(1,3)\}$ to obtain the sequence $((1,3))$. - Arrange the set $\{(3,2)\}$ to obtain the sequence $((3,2))$. - Concatenate the resulting two sequences to obtain the sequence $((1,3),(3,2))$. - Concatenate the resulting two sequences to obtain the sequence $((2,1),(1,3),(3,2))$.
Input #2
5
1 2 3 4 5
Output #2
1
Input #3
10
3 6 4 8 7 2 10 5 9 1
Output #3
1332
Input #4
30
7 11 8 26 4 13 28 5 14 1 16 27 10 2 23 25 17 6 3 18 24 15 9 22 21 29 12 20 19 30
Output #4
641915679
题目信息
题号
arc138_f
时间限制
4 s
内存限制
1024 MB

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