Traces of Binary Search
Time limit1sMemory limit1024 MB
Given N and a binary search trace of probed values, count the strictly increasing arrays with values from 1 to 100 that produce that exact trace, modulo 10^9+7.
- Level
Medium6 of 10
- Topics
- Binary search, Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
Geon-i and Junseong play a game with a sorted array of length . Junseong picks one element of the array at random. The answer range is the range of indices where the element Junseong picked could be, and it starts as .
Geon-i can pick an element in the current answer range and ask whether the number he is thinking of is that element. Junseong answers with one of Yes, Up, or Down. Junseong does not lie, and the game ends when Junseong answers Yes. The sequence of the elements Geon-i asked, in order, is called the trace of binary search.
Geon-i always makes the best choice in every game, so when the answer range is , he always asks about .
- If Junseong answers Up, the next range is .
- If Junseong answers Down, the next range is .
Given a trace of binary search, print the number of arrays that could produce it.
Input
The first line contains the size of the array and the size of the trace, separated by a space.
The second line contains the integers that make up the trace, separated by spaces.
Output
Print the number of possible arrays , modulo .
Constraints
- For all ,
- Only traces for which at least one possible array exists are given as input.