A14665 | Mathematics Curriculum
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Let $c_1, c_2, \ldots, c_n$ be a permutation of integers $1, 2, \ldots, n$ . Consider all subsegments of this permutation containing an integer $x$ . Given an integer $m$ , we call the integer $x$ good if there are exactly $m$ different values of maximum on these subsegments.
Cirno is studying mathematics, and the teacher asks her to count the number of permutations of length $n$ with exactly $k$ good numbers.
Unfortunately, Cirno isn't good at mathematics, and she can't answer this question. Therefore, she asks you for help.
Since the answer may be very big, you only need to tell her the number of permutations modulo $p$ .
A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ( $2$ appears twice in the array) and $[1,3,4]$ is also not a permutation ( $n=3$ but there is $4$ in the array).
A sequence $a$ is a subsegment of a sequence $b$ if $a$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.
Cirno is studying mathematics, and the teacher asks her to count the number of permutations of length $n$ with exactly $k$ good numbers.
Unfortunately, Cirno isn't good at mathematics, and she can't answer this question. Therefore, she asks you for help.
Since the answer may be very big, you only need to tell her the number of permutations modulo $p$ .
A permutation is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ( $2$ appears twice in the array) and $[1,3,4]$ is also not a permutation ( $n=3$ but there is $4$ in the array).
A sequence $a$ is a subsegment of a sequence $b$ if $a$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.
输入格式
The first line contains four integers $n, m, k, p$ ( $1 \le n \le 100, 1 \le m \le n, 1 \le k \le n, 1 \le p \le 10^9$ ).
输出格式
Output the number of permutations modulo $p$ .
输入输出样例
输入 #1
4 3 2 10007
输出 #1
4
输入 #2
6 4 1 769626776
输出 #2
472
输入 #3
66 11 9 786747482
输出 #3
206331312
输入 #4
99 30 18 650457567
输出 #4
77365367
In the first test case, there are four permutations: $[1, 3, 2, 4]$ , $[2, 3, 1, 4]$ , $[4, 1, 3, 2]$ and $[4, 2, 3, 1]$ .
Take permutation $[1, 3, 2, 4]$ as an example:
For number $1$ , all subsegments containing it are: $[1]$ , $[1, 3]$ , $[1, 3, 2]$ and $[1, 3, 2, 4]$ , and there're three different maxima $1$ , $3$ and $4$ .
Similarly, for number $3$ , there're two different maxima $3$ and $4$ . For number $2$ , there're three different maxima $2$ , $3$ and $4$ . And for number $4$ , there're only one, that is $4$ itself.
Take permutation $[1, 3, 2, 4]$ as an example:
For number $1$ , all subsegments containing it are: $[1]$ , $[1, 3]$ , $[1, 3, 2]$ and $[1, 3, 2, 4]$ , and there're three different maxima $1$ , $3$ and $4$ .
Similarly, for number $3$ , there're two different maxima $3$ and $4$ . For number $2$ , there're three different maxima $2$ , $3$ and $4$ . And for number $4$ , there're only one, that is $4$ itself.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted