#abc282g. G - Similar Permutation

G - Similar Permutation

Score : 600600 points

问题描述

以下,我们将 (1,2,,N)(1,2,\ldots,N) 的一个排列简单地称为一个排列。

对于两个排列 A=(A1,A2,,AN)A=(A_1,A_2,\ldots,A_N)B=(B1,B2,,BN)B=(B_1,B_2,\ldots,B_N),我们定义它们的 相似度 为满足下列条件的整数 ii(其中 ii 取值范围在 11N1N-1 之间)的数量:

  • (Ai+1Ai)(Bi+1Bi)>0(A_{i+1}-A_i)(B_{i+1}-B_i)>0

求出相似度为 KK 的排列对 (A,B)(A,B) 的数量模一个素数 PP 的结果。

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

Problem Statement

Below, a permutation of (1,2,,N)(1,2,\ldots,N) is simply called a permutation.

For two permutations A=(A1,A2,,AN),B=(B1,B2,,BN)A=(A_1,A_2,\ldots,A_N),B=(B_1,B_2,\ldots,B_N), let us define their similarity as the number of integers ii between 11 and N1N-1 such that:

  • (Ai+1Ai)(Bi+1Bi)>0(A_{i+1}-A_i)(B_{i+1}-B_i)>0.

Find the number, modulo a prime number PP, of pairs of permutations (A,B)(A,B) whose similarity is KK.

Constraints

  • 2N1002\leq N \leq 100
  • 0KN10\leq K \leq N-1
  • 108P10910^8 \leq P \leq 10^9
  • PP is a prime number.
  • All values in the input are integers.

Input

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

NN KK PP

Output

Print the answer.

Sample Input 1

3 1 282282277

Sample Output 1

16

For instance, below is a pair of permutations that satisfies the condition.

  • A=(1,2,3)A=(1,2,3)
  • B=(1,3,2)B=(1,3,2)

Here, we have (A2A1)(B2B1)>0(A_2 - A_1)(B_2 -B_1) > 0 and (A3A2)(B3B2)<0(A_3 - A_2)(B_3 -B_2) < 0, so the similarity of AA and BB is 11.

Sample Input 2

50 25 998244353

Sample Output 2

131276976

Print the number modulo PP.

update @ 2024/3/10 11:51:07