CF1580B.Mathematics Curriculum

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Let c1,c2,…,cnc_1, c_2, \ldots, c_n be a permutation of integers 1,2,…,n1, 2, \ldots, n. Consider all subsegments of this permutation containing an integer xx. Given an integer mm, we call the integer xx good if there are exactly mm different values of maximum on these subsegments.

Cirno is studying mathematics, and the teacher asks her to count the number of permutations of length nn with exactly kk 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 pp.

A permutation is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array) and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).

A sequence aa is a subsegment of a sequence bb if aa can be obtained from bb by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

设 c1,c2,…,cnc_1, c_2, \ldots, c_n 是整数 1,2,…,n1, 2, \ldots, n 的一个排列。考虑该排列中所有包含整数 xx 的子段(连续子数组)。给定整数 mm,若在这些子段中,最大值恰好有 mm 个不同的取值,则称整数 xx 是“好的”。

琪露诺正在学习数学,老师让她计算长度为 nn 且恰好有 kk 个“好”的数的排列个数。

不幸的是,琪露诺不擅长数学,无法回答这个问题。因此,她向你求助。

由于答案可能非常大,你只需输出答案对 pp 取模的结果。

一个排列是由 11 到 nn 中 nn 个互不相同的整数组成的数组,顺序任意。例如,[2,3,1,5,4][2,3,1,5,4] 是一个排列,但 [1,2,2][1,2,2] 不是排列(数组中 22 出现了两次),[1,3,4][1,3,4] 也不是排列(此时 n=3n=3,但数组中出现了 44)。

若序列 aa 可通过从序列 bb 的开头删除若干(可能为零或全部)元素、并从结尾删除若干(可能为零或全部)元素而得到,则称 aa 是 bb 的一个子段。

输入格式

The first line contains four integers n,m,k,pn, m, k, p (1≤n≤100,1≤m≤n,1≤k≤n,1≤p≤1091 \le n \le 100, 1 \le m \le n, 1 \le k \le n, 1 \le p \le 10^9).

第一行包含四个整数 n,m,k,pn, m, k, p(1≤n≤1001 \le n \le 100,1≤m≤n1 \le m \le n,1≤k≤n1 \le k \le n,1≤p≤1091 \le p \le 10^9)。

输出格式

Output the number of permutations modulo pp.

输出排列数对 pp 取模的结果。

输入输出样例

  • 输入#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][1, 3, 2, 4], [2,3,1,4][2, 3, 1, 4], [4,1,3,2][4, 1, 3, 2] and [4,2,3,1][4, 2, 3, 1].

Take permutation [1,3,2,4][1, 3, 2, 4] as an example:

For number 11, all subsegments containing it are: [1][1], [1,3][1, 3], [1,3,2][1, 3, 2] and [1,3,2,4][1, 3, 2, 4], and there're three different maxima 11, 33 and 44.

Similarly, for number 33, there're two different maxima 33 and 44. For number 22, there're three different maxima 22, 33 and 44. And for number 44, there're only one, that is 44 itself.

在第一个测试用例中,共有四个排列:[1,3,2,4][1, 3, 2, 4]、[2,3,1,4][2, 3, 1, 4]、[4,1,3,2][4, 1, 3, 2] 和 [4,2,3,1][4, 2, 3, 1]。

以排列 [1,3,2,4][1, 3, 2, 4] 为例:

对于数字 11,包含它的所有子段为:[1][1]、[1,3][1, 3]、[1,3,2][1, 3, 2] 和 [1,3,2,4][1, 3, 2, 4],其中出现的不同最大值有 11、33 和 44,共三个。

类似地,对于数字 33,出现的不同最大值有 33 和 44,共两个;对于数字 22,出现的不同最大值有 22、33 和 44,共三个;而对于数字 44,仅有一个不同最大值,即其自身 44。

输入解题思路,AI测评打分。不知道怎么写?

首页