103236: [Atcoder]ABC323 G - Inversion of Tree
Description
Score : $650$ points
Problem Statement
You are given a permutation $P=(P_1,P_2,\ldots,P_N)$ of $(1,2,\ldots,N)$.
For each $K=0,1,\ldots,N-1$, find the number, modulo $998244353$, of trees with $N$ vertices numbered $1$ to $N$ that satisfy the following condition.
- Among the pairs of vertices $(u_i,v_i)\ (u_i < v_i)$ that are directly connected by an edge in the tree, exactly $K$ pairs satisfy $P_{u_i}>P_{v_i}$.
Constraints
- $2\leq N\leq 500$
- $P$ is a permutation of $(1,2,\ldots,N)$.
Input
The input is given from Standard Input in the following format:
$N$ $P_1$ $P_2$ $\ldots$ $P_N$
Output
For each $K=0,1,\ldots,N-1$, print the number, modulo $998244353$, of trees that satisfy the condition, with spaces in between.
Sample Input 1
3 1 3 2
Sample Output 1
1 2 0
The answer for $K=0$ is $1$: the tree with edges connecting vertices $1,2$ and $1,3$. Indeed, $P_1 < P_2$ and $P_1<P_3$.
The answer for $K=1$ is $2$: the tree with edges connecting vertices $1,2$ and $2,3$, and another with edges connecting vertices $1,3$ and $2,3$. Indeed, in the tree with edges connecting vertices $1,2$ and $2,3$, we have $P_1 < P_2$, $P_2>P_3$.
Sample Input 2
10 3 1 4 10 8 6 9 2 7 5
Sample Output 2
294448 2989776 12112684 25422152 30002820 20184912 7484084 1397576 108908 2640
Input
Output
问题描述
给定一个排列$P=(P_1,P_2,\ldots,P_N)$,其中$(1,2,\ldots,N)$的排列。
对于每个$K=0,1,\ldots,N-1$,求满足以下条件的有$N$个顶点的树的数量,模$998244353$。
- 在树中直接由边连接的顶点对$(u_i,v_i)\ (u_i < v_i)$中,恰好有$K$对满足$P_{u_i}>P_{v_i}$。
约束条件
- $2\leq N\leq 500$
- $P$是$(1,2,\ldots,N)$的排列。
输入
输入从标准输入按以下格式给出:
$N$ $P_1$ $P_2$ $\ldots$ $P_N$
输出
对于每个$K=0,1,\ldots,N-1$,输出满足条件的树的数量,模$998244353$,之间用空格隔开。
样例输入1
3 1 3 2
样例输出1
1 2 0
对于$K=0$,答案为$1$:有边连接顶点$1,2$和$1,3$的树。确实,$P_1 < P_2$和$P_1<P_3$。
对于$K=1$,答案为$2$:有边连接顶点$1,2$和$2,3$的树,以及有边连接顶点$1,3$和$2,3$的树。确实,在有边连接顶点$1,2$和$2,3$的树中,我们有$P_1 < P_2$,$P_2>P_3$。
样例输入2
10 3 1 4 10 8 6 9 2 7 5
样例输出2
294448 2989776 12112684 25422152 30002820 20184912 7484084 1397576 108908 2640