#P8699. Counting Monotonic Permutations

    ID: 21863 Type: Default 1000ms 256MiB

Counting Monotonic Permutations

Counting Monotonic Permutations

Let a bend point in a permutation be an element that is either smaller than both of its neighbors or greater than both. For a permutation of \(1 \sim n\), if it contains \(t\) bend points, then it is called a \(t+1\)-monotonic permutation. For example, the permutation \((1, 4, 2, 3)\) is a 3-monotonic permutation because both 4 and 2 are bend points (since \(4>1,4>2\) and \(2<4,2<3\)).

Given two integers \(n\) and \(k\), count the number of \(k\)-monotonic permutations among all the permutations of \(\{1,2,\ldots,n\}\). In other words, count the number of permutations which contain exactly \(k-1\) bend points.

Note: For \(n=1\), only \(k=1\) is valid.

inputFormat

The input consists of a single line containing two integers \(n\) and \(k\) separated by a space.

\(n\): the size of the permutation.\ \(k\): the monotonic measure (which equals the number of bend points plus one).

outputFormat

Output a single integer representing the number of \(k\)-monotonic permutations of \(\{1,2,\ldots,n\}\).

sample

1 1
1