#P8554. 心跳

    ID: 9806 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>动态规划 DP洛谷原创O2优化洛谷月赛

心跳

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 pp of length ll, define the function:

  • f(p)f(p) is the number of indices 1il1 \le i \le l such that pi=maxj=1ipjp_i = \max_{j=1}^i p_j (that is, the number of prefix maxima).

Now, given n,mn, m, compute how many sequences aa of length nn with values in [m,n][m, n] satisfy the following condition:

  • There exists a permutation pp such that: let PiP_i denote the sequence obtained from pp by removing pip_i (that is, [p1,p2,,pi1,pi+1,,pn][p_1,p_2,\dots,p_{i-1},p_{i+1},\dots,p_n]), and f(Pi)=aif(P_i) = a_i.

Output the answer modulo 109+710^9+7.

Input Format

One line contains two positive integers n,mn, m.

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 88 different sequences aa:

  1. {4,4,4,4,4}\{4,4,4,4,4\}, one corresponding pp is {1,2,3,4,5}\{1,2,3,4,5\}.
  2. {3,3,3,4,4}\{3,3,3,4,4\}, one corresponding pp is {1,2,3,5,4}\{1,2,3,5,4\}.
  3. {3,3,4,4,3}\{3,3,4,4,3\}, one corresponding pp is {1,2,4,3,5}\{1,2,4,3,5\}.
  4. {3,3,3,3,4}\{3,3,3,3,4\}, one corresponding pp is {1,2,4,5,3}\{1,2,4,5,3\}.
  5. {3,4,4,3,3}\{3,4,4,3,3\}, one corresponding pp is {1,3,2,4,5}\{1,3,2,4,5\}.
  6. {3,3,3,4,3}\{3,3,3,4,3\}, one corresponding pp is {1,3,4,2,5}\{1,3,4,2,5\}.
  7. {4,4,3,3,3}\{4,4,3,3,3\}, one corresponding pp is {2,1,3,4,5}\{2,1,3,4,5\}.
  8. {3,3,4,3,3}\{3,3,4,3,3\}, one corresponding pp is {2,3,1,4,5}\{2,3,1,4,5\}.

[Constraints]

For all testdata, it is guaranteed that 3n2000,1mn3 \le n \le 2000, 1 \le m \le n.

$$\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