#P15658. [ICPC 2025 Jakarta R] Count DFS Graph

[ICPC 2025 Jakarta R] Count DFS Graph

题目描述

You are currently researching a graph traversal algorithm called the Depth First Search (DFS). Starting with an empty list A\texttt{A}, the following pseudocode will fill the list A\texttt{A} with the visitation order of a DFS algorithm.

    DFS(v):
        append v to A
        for each u neighbour of v in ascending node number:
            if u is not in A:
                DFS(u)

After running DFS(1)\texttt{DFS(1)} from the pseudocode above, you now have a list AA containing a permutation of integers from 11 to NN. You now wonder how many different simple undirected graphs with NN nodes there are that yield the list AA that you have. Count the number, modulo 998244353998\,244\,353.

A graph is simple when there are no self-loops and there is at most one edge connecting each pair of nodes. Two graphs are considered different if there is an edge connecting a pair of nodes in one graph but not the other.

输入格式

The first line contains an integer NN (2N3002 \le N \le 300).

The second line contains a permutation of the first NN positive integers, representing the list AA.

The first element of AA is guaranteed to be 11.

输出格式

A single integer representing the number of different graphs, whose DFS order gives you the list AA, modulo 998244353998\,244\,353.

4
1 3 4 2
3
10
1 2 3 4 5 6 7 8 9 10
515546413

提示

Explanation of Sample 1:\textit{Explanation of Sample 1:} The following illustrates all the graphs with the given DFS order.

:::align{center} :::