Local Minimum-Maximum

3.5

2 votes
Medium
Problem

For a given array of distinct n integers A[1..n] and two integers X and Y, the goal is to find the number of subsequences of A with exactly X local minimums and Y local maximums. For a subsequence A[i1],A[i2],,A[ik] of A, element A[ij] for 1<ij<k is a local minimum if and only if A[ij1]>A[ij]<A[ij+1]. Similarly, A[ij] is a local maximum if and only if A[ij1]<A[ij]>A[ij+1].

Since the result can be very big, the goal is to return it modulo 109+9.

Input format:

In the first line there are 3 integers n,X,Y, denoting correspondently the size of the input array, the number of local minimums in desired subsequences, and the number of local maximums in desired subsequences.

In the second line, there are n space separated integers denoting the array A.

Output format:

In one line, output a single integer denoting the number of subsequences of array A with exactly X local minimums and exactly Y local maximums computed modulo 109+9.

Constraints:

3n1000
0X,Y50

Sample Input
4 0 1
1 3 5 4
Sample Output
3
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

The goal is to count the number of subsequences of [1,3,5,4] with exactly 0 local minimums and exactly 1 local maximum. There are 3 such subsequences: [1,5,4],[3,5,4] and [1,3,5,4].

Editor Image

?