#P8699. [蓝桥杯 2019 国 B] 排列数

[蓝桥杯 2019 国 B] 排列数

Problem Description

In a permutation, a turning point is an element in the permutation that is either smaller than both of its adjacent elements, or larger than both of its adjacent elements.

For a permutation of 1n1 \sim n, if the permutation contains tt turning points, then it is called a (t+1)(t + 1)-monotone permutation.

For example, the permutation (1,4,2,3)(1, 4, 2, 3) is a 33-monotone permutation, where 44 and 22 are both turning points.

Given nn and kk, how many permutations of 1n1 \sim n are kk-monotone permutations?

Input Format

One line contains two integers nn and kk.

Output Format

Output one integer, representing the answer. The answer may be very large, so you only need to output the remainder when the number of valid permutations is divided by 123456123456.

4 2

12

Hint

For 20%20\% of the test cases, 1kn101 \leq k \leq n \leq 10.

For 40%40\% of the test cases, 1kn201 \leq k \leq n \leq 20.

For 60%60\% of the test cases, 1kn1001 \leq k \leq n \leq 100.

For all test cases, 1kn5001 \leq k \leq n \leq 500.

Lanqiao Cup 2019 National Contest, Group B, Problem G.

Translated by ChatGPT 5