#P8554. Counting Feasible Removal‐Record Sequences
Counting Feasible Removal‐Record Sequences
Counting Feasible Removal‐Record Sequences
Let a permutation p of n be an ordering of the numbers {1,2,…,n}. For any sequence q of length l we define f(q) to be the number of indices i (1 ≤ i ≤ l) for which
[ q_i = \max{q_1,q_2,\dots,q_i}, ]
i.e. the number of records (or left‐to‐right maxima) in the sequence. For a permutation p of length n and each index i (1 ≤ i ≤ n) let Pi be the sequence obtained by removing the ith element from p. Then define an array a of length n by
[ a_i = f(P_i) \quad \text{for } 1 \le i \le n. ]
We say that an array a (of length n) is feasible if there exists a permutation p of {1,2,…,n} such that the above equation holds. Note that by definition the values of a come from the computation of f on permutations of length n-1 (or, in the case n = 1, an empty sequence — we take f([])=0). Thus when n > 1 a feasible array always has each entry between 1 and n-1, while for n = 1 the only feasible array is [0].
Given two integers n and m, count how many arrays a of length n with each element in the interval [m, n] are feasible (i.e. there exists a permutation p that produces a via the above process). Since the answer may be large, output it modulo \(10^9+7\).
Note: An array a = (a1, a2, …, an) is considered only once even if there are several permutations producing it.
inputFormat
The first and only line of input contains two integers n and m separated by a space.
Constraints:
For this problem, it is guaranteed that n is small (e.g. n ≤ 8) so that a brute‐force solution over all n! permutations is feasible.
outputFormat
Output a single integer, the number of feasible arrays a with each element in [m, n] modulo \(10^9+7\).
sample
3 1
6