Erasing Game
Time limit1sMemory limit128 MB
Count the ordered sequences A whose entries can each be matched to a distinct entry of S that is at least as large.
- Level
Medium7 of 10
- Topics
- Combinatorics, Sorting, Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
Hongjun and Myungwoo play a game with sequences. Hongjun first writes down a sequence of natural numbers, chosen however he likes, and Myungwoo writes down a sequence of the same length in the same way.
The game runs for rounds. In round , Hongjun has to erase one number from his own sequence that is not greater than . If no such number is left, Hongjun loses. If he finishes all rounds, Hongjun wins.
Given Myungwoo's sequence , count the sequences that let Hongjun win when he plays with an optimal strategy. Two sequences with the same numbers in a different order count as different sequences.
Input
The first line contains the length . ()
The -th of the next lines contains . ()
Output
Print the number of sequences that Hongjun can win with, modulo 1,000,000,007.
Hint
For and , the sequences that Hongjun can win with are , , and .