#P8554. 心跳
心跳
Background
“The clear sound of a heartbeat carries overlapping echoes and flowing longing.
Let’s promise never to be apart again, and hope that no matter when, you will not feel lonely.”
When people are in love, their feelings do not stay the same. Joy and sadness will both fade into calm as time passes. What is most unforgettable is the feeling of “being moved,” the kind of surprise and happiness from things you have never experienced before. Therefore, sometimes, losing some especially beautiful memories can instead make that “heartbeat” feeling happen more often. But is it really worth losing those memories for it?
Problem Description
Helde wants to study the question above. She plans to collect some statistics first, so she abstracts the problem.
For a sequence of length , define the function:
- is the number of indices such that (that is, the number of prefix maxima).
Now, given , compute how many sequences of length with values in satisfy the following condition:
- There exists a permutation such that: let denote the sequence obtained from by removing (that is, ), and .
Output the answer modulo .
Input Format
One line contains two positive integers .
Output Format
One line contains one number, the answer.
3 1
6
5 3
8
50 10
664411387
Hint
[Sample Explanation #2]
There are the following different sequences :
- , one corresponding is .
- , one corresponding is .
- , one corresponding is .
- , one corresponding is .
- , one corresponding is .
- , one corresponding is .
- , one corresponding is .
- , one corresponding is .
[Constraints]
For all testdata, it is guaranteed that .
$$\def\arraystretch{1.5} \begin{array}{c|c|c|c}\hline \textbf{Subtask ID}&~~\bm{n\le} ~~&~~\bm{m\le}~~ &\textbf{Score}\cr\hline \textsf1 & 9 &1&8\cr\hline \textsf2 & 18&1&12 \cr\hline \textsf3 & 70&1&15\cr\hline \textsf4 & 70 &&24\cr\hline \textsf5 & 300&&18 \cr\hline \textsf6 & &&23\cr\hline\end{array}$$If it is not written, then there is no special restriction.
Helde successfully computed the number of different kinds of love. But she will only experience one of them.
Translated by ChatGPT 5