#P15971. [Aboi 2077] Permutation Counting 3

    ID: 17929 远端评测题 4000ms 128MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>组合数学容斥原理生成函数2077

[Aboi 2077] Permutation Counting 3

Background

Problem Description

Given nn, for each pair x∈[0,n)x \in [0, n) and y∈[1,n]y \in [1, n], find how many permutations pp of 1∼n1 \sim n satisfy the following conditions:

  • ∑i=1n−1[pi<pi+1]=x\sum\limits_{i=1}^{n-1} [p_i < p_{i+1}] = x.
  • There are exactly yy permutation cycles in pp.

Take the answer modulo the given prime PP.

Input Format

One line with two positive integers n,Pn, P.

Output Format

Output nn lines, each containing nn integers. The number in row ii and column jj represents the answer when x=i−1x = i - 1 and y=jy = j.

3 1000000007
0 1 0
2 2 0
0 0 1
5 1000000007
0 0 1 0 0
6 12 8 0 0
12 30 18 6 0
6 8 8 4 0
0 0 0 0 1
10 1000000007
0 0 0 0 1 0 0 0 0 0
105 286 341 195 71 15 0 0 0 0
4773 14122 16301 9444 2819 381 0 0 0 0
45525 132768 153353 90556 28471 4299 220 0 0 0
131049 375730 431900 261660 90786 17649 1580 0 0 0
131019 367570 418355 261804 101865 25710 3800 231 0 0
45519 123618 138737 90477 40295 13061 3072 413 0 0
4791 12256 13479 9353 4901 2081 740 203 36 0
99 226 234 191 116 77 38 23 9 0
0 0 0 0 0 0 0 0 0 1

Hint

Constraints: For all testdata, 1≤n≤2001 \le n \le 200, 9.9×108≤P≤1.01×1099.9 \times 10^8 \le P \le 1.01 \times 10^9, and PP is guaranteed to be prime.

Click here to view another version of this problem。

Translated by ChatGPT 5