#P16608. [SYSUCPC 2025] Larger or Smaller

    ID: 16377 Type: RemoteJudge 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 7 Uploaded By: Tags>动态规划 DP2025组合数学高校校赛

[SYSUCPC 2025] Larger or Smaller

题目描述

In his recent work on permutation properties, Dr.Z\texttt{Dr.Z} investigates the relationship between element values and their indices. A key focus is the cardinality of the set of indices ii where pi>ip_i>i (called larger position\bf{larger\ position}) and where pi<ip_i<i (called smaller position\bf{smaller\ position}). To formalize this, he defines f(n,x,y)f(n,x,y) as the number of permutations of nn elements containing exactly xx larger positions and yy smaller positions. Dr.Z\texttt{Dr.Z} now aims to characterize this function completely by determining the values of f(n,x,y)f(n,x,y) across all valid positive integers xx and yy after modulo mm. Could you help him solve this problem efficiently?

输入格式

The only line contains two integers n,m(2n2000,2m109+7)n,m(2\le n\le 2000,2\le m\le 10^9+7).

输出格式

There are n1n-1 rows in total. The ii-th row contains nin-i integers. The jj-th integer represents the result of f(n,i,j)f(n,i,j) modulo mm.

5 998244353
10 10 5 1
10 35 21
5 21
1

提示

The five permutations of x=1,y=3x=1,y=3 are [1,5,2,3,4],[4,1,2,3,5],[5,1,2,4,3],[5,1,3,2,4][1,5,2,3,4], [4,1,2,3,5], [5,1,2,4,3], [5,1,3,2,4], and [5,2,1,3,4][5,2,1,3,4].