#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 , if the permutation contains turning points, then it is called a -monotone permutation.
For example, the permutation is a -monotone permutation, where and are both turning points.
Given and , how many permutations of are -monotone permutations?
Input Format
One line contains two integers and .
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 .
4 2
12
Hint
For of the test cases, .
For of the test cases, .
For of the test cases, .
For all test cases, .
Lanqiao Cup 2019 National Contest, Group B, Problem G.
Translated by ChatGPT 5