Skyline
Time limit1sMemory limit128 MB
Count permutations of 1..N with no increasing subsequence of length 3, modulo 1,000,000, for each N up to 1,000.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Combinatorics, Math
- Solved
- No attempts yet
Problem
The director of a new movie needs to build a scaled-down set for the film. The set will contain skyscrapers whose heights are distinct integers from to meters. The skyline is the sequence of the buildings' heights read from left to right, so it is a permutation of the integers from to .
The director is extremely meticulous and wants to avoid one particular rising pattern: she does not want ANY three buildings at positions with such that the height of building is smaller than that of building and the height of building is smaller than that of building .
For a given number of buildings, determine how many distinct skyline orderings avoid the rising pattern she dislikes.
Input
The input contains several test cases. Each test case is a single line containing one integer , the number of skyscrapers. Their heights are assumed to be . The input ends with a line containing a single .
Output
For each test case, output a single integer: the number of good skylines — those that avoid the rising pattern the director dislikes — modulo . Print each integer on its own line with no spaces, and do not print any blank lines between answers.