102826: [AtCoder]ABC282 G - Similar Permutation

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $600$ points

Problem Statement

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

For two permutations $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 $i$ between $1$ and $N-1$ such that:

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

Find the number, modulo a prime number $P$, of pairs of permutations $(A,B)$ whose similarity is $K$.

Constraints

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

Input

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

$N$ $K$ $P$

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)$
  • $B=(1,3,2)$

Here, we have $(A_2 - A_1)(B_2 -B_1) > 0$ and $(A_3 - A_2)(B_3 -B_2) < 0$, so the similarity of $A$ and $B$ is $1$.


Sample Input 2

50 25 998244353

Sample Output 2

131276976

Print the number modulo $P$.

Input

题意翻译

长为 $N$ 的排列 $A$ 与 $B$ 的相似度被定义为: - 满足 $(A_{i+1}-A_i)(B_{i+1}-B_i)>0$,其中 $1\le i<N$ 的 $i$ 的数量。 求有多少对 $1\sim N$ 的排列相似度恰为 $K$,对 $P$ 取模。

Output

分数:$600$分

问题描述

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

对于两个排列$A=(A_1,A_2,\ldots,A_N),B=(B_1,B_2,\ldots,B_N)$,我们定义它们的相似度为满足以下条件的整数$i$的数量:

  • $(A_{i+1}-A_i)(B_{i+1}-B_i)>0$。

求相似度为$K$的排列$(A,B)$的对数,对一个素数$P$取模。

约束条件

  • $2\leq N \leq 100$
  • $0\leq K \leq N-1$
  • $10^8 \leq P \leq 10^9$
  • $P$是素数。
  • 输入中的所有值都是整数。

输入

输入从标准输入按以下格式给出:

$N$ $K$ $P$

输出

输出答案。


样例输入1

3 1 282282277

样例输出1

16

例如,下面是一对满足条件的排列。

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

这里,我们有$(A_2 - A_1)(B_2 -B_1) > 0$和$(A_3 - A_2)(B_3 -B_2) < 0$,所以$A$和$B$的相似度为$1$。


样例输入2

50 25 998244353

样例输出2

131276976

输出对$P$取模的结果。

加入题单

算法标签: