#P5853. [USACO19DEC] Tree Depth P

    ID: 4801 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>数学2019USACO组合数学生成函数

[USACO19DEC] Tree Depth P

Description

For the new year, Farmer John decided to give his cows a festive binary search tree (BST)!

To generate the BST, FJ starts with a permutation a={a1,a2,,aN}a=\{a_1,a_2,\ldots,a_N\} of the integers 1N1\ldots N, where N300N\le 300. He then runs the following pseudocode with arguments 11 and N.N.

generate(l,r):
  if l > r, return empty subtree;
  x = argmin_{l <= i <= r} a_i; // index of min a_i in {a_l,...,a_r}
  return a BST with x as the root, 
    generate(l,x-1) as the left subtree,
    generate(x+1,r) as the right subtree;

For example, the permutation {3,2,5,1,4}\{3,2,5,1,4\} generates the following BST:

    4
   / \
  2   5
 / \ 
1   3

Let di(a)d_i(a) denote the depth of node ii in the tree corresponding to a,a, meaning the number of nodes on the path from aia_i to the root. In the above example, d4(a)=1,d2(a)=d5(a)=2,d_4(a)=1, d_2(a)=d_5(a)=2, and d1(a)=d3(a)=3.d_1(a)=d_3(a)=3.

The number of inversions of aa is equal to the number of pairs of integers (i,j)(i,j) such that 1i<jN1\le i<j\le N and ai>aj.a_i>a_j. The cows know that the aa that FJ will use to generate the BST has exactly KK inversions (0KN(N1)2)(0\le K\le \frac{N(N-1)}{2}). Over all aa satisfying this condition, compute the remainder when adi(a)\sum_ad_i(a) is divided by MM for each 1iN.1\le i\le N.

Input Format

The only line of input consists of three space-separated integers N,KN,K,and MM, followed by a new line. MM will be a prime number in the range [108,109+9][10^8,10^9+9].

Output Format

Print NN space-separated integers denoting adi(a)(modM)\sum_a d_i(a) (\bmod M) for each 1iN1\leq i\leq N

3 0 192603497

1 2 3

3 1 144408983

3 4 4

Hint

Sample Explanation

For the first example,the only permutation is a={1,2,3}a=\{1,2,3\}.

For the second example,the two permutations are a={1,3,2}a=\{1,3,2\} and a={2,1,3}a=\{2,1,3\}.

Data range

Test cases 343-4 satisfy N8N\leq 8.
Test cases 575-7 satisfy N20N\leq 20.
Test cases 8108-10 satisfy N50N\leq 50.