QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 512 MB Total points: 100

#7759. Permutation Counting 2

统计

给定 $ n $,对于每组 $ x,y\in [0,n) $ 求出有多少个 $ 1\sim n $ 的排列 $ p $ 满足以下条件:

  • $ \sum\limits_{i=1}^{n-1}[p_i < p_{i+1}]=x $。
  • $ \sum\limits_{i=1}^{n-1}[p^{-1}_i < p^{-1}_{i+1}]=y $。

其中 $ p^{-1} $ 表示 $ p $ 的逆排列,满足 $ p^{-1}_{p_i}=i $。

答案对给定的质数 $ MOD $ 取模。

输入格式

共一行,两个整数,表示 $ n,MOD $。

输出格式

共 $ n $ 行,每行共 $ n $ 个整数,第 $ i $ 行第 $ j $ 列的数表示 $ x=i-1,y=j-1 $ 时的答案。

样例

样例输入 1

3 1000000007

样例输出 1

1 0 0
0 4 0
0 0 1

样例输入 2

5 1000000007

样例输出 2

1 0 0 0 0
0 20 6 0 0
0 6 54 6 0
0 0 6 20 0
0 0 0 0 1

样例输入 3

10 1000000007

样例输出 3

1 0 0 0 0 0 0 0 0 0
0 165 462 330 55 1 0 0 0 0
0 462 9273 22023 13750 2266 66 0 0 0
0 330 22023 147301 203610 75306 6556 66 0 0 
0 55 13750 203610 592130 423236 75306 2266 1 0
0 1 2266 75306 423236 592130 203610 13750 55 0
0 0 66 6556 75306 203610 147301 22023 330 0
0 0 0 66 2266 13750 22023 9273 462 0
0 0 0 0 1 55 330 462 165 0
0 0 0 0 0 0 0 0 0 1

数据范围

对于 $ 100\% $ 数据,$ 1\le n\le 500,10^9\le MOD\le 1.01\times 10^9 $,保证 $ MOD $ 为质数。

$ \operatorname{Subtask} 1(10\%):n\le 8 $。

$ \operatorname{Subtask} 2(15\%):n\le 16 $。

$ \operatorname{Subtask} 3(25\%):n\le 40 $。

$ \operatorname{Subtask} 4(25\%):n\le 100 $。

$ \operatorname{Subtask} 5(25\%): $ 无特殊限制。

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.