#abc323g. G - Inversion of Tree

G - Inversion of Tree

Score : 650650 points

问题描述

给定一个由 (1,2,,N)(1,2,\ldots,N) 的排列 P=(P1,P2,,PN)P=(P_1,P_2,\ldots,P_N)

对于每个 K=0,1,,N1K=0,1,\ldots,N-1,找出满足以下条件的有 NN 个顶点(编号为 11NN)的树的数量,计算结果对 998244353998244353 取模。

  • 在树中直接通过边相连的顶点对 (ui,vi) (ui<vi)(u_i,v_i)\ (u_i < v_i) 中,恰好有 KK 对满足 Pui>PviP_{u_i}>P_{v_i}

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given a permutation P=(P1,P2,,PN)P=(P_1,P_2,\ldots,P_N) of (1,2,,N)(1,2,\ldots,N).

For each K=0,1,,N1K=0,1,\ldots,N-1, find the number, modulo 998244353998244353, of trees with NN vertices numbered 11 to NN that satisfy the following condition.

  • Among the pairs of vertices (ui,vi) (ui<vi)(u_i,v_i)\ (u_i < v_i) that are directly connected by an edge in the tree, exactly KK pairs satisfy Pui>PviP_{u_i}>P_{v_i}.

Constraints

  • 2N5002\leq N\leq 500
  • PP is a permutation of (1,2,,N)(1,2,\ldots,N).

Input

The input is given from Standard Input in the following format:

NN

P1P_1 P2P_2 \ldots PNP_N

Output

For each K=0,1,,N1K=0,1,\ldots,N-1, print the number, modulo 998244353998244353, 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=0K=0 is 11: the tree with edges connecting vertices 1,21,2 and 1,31,3. Indeed, P1<P2P_1 < P_2 and P1<P3P_1<P_3.

The answer for K=1K=1 is 22: the tree with edges connecting vertices 1,21,2 and 2,32,3, and another with edges connecting vertices 1,31,3 and 2,32,3. Indeed, in the tree with edges connecting vertices 1,21,2 and 2,32,3, we have P1<P2P_1 < P_2, P2>P3P_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

update @ 2024/3/10 01:45:30