Mountains
Time limit1sMemory limit256 MB
Count n by m grids of non-negative heights, each at most k, whose maximum-weight monotone path from (1,1) to (n,m) has total sum at most k.
- Level
Hard9 of 10
- Topics
- Dynamic programming, Combinatorics, Math
- Solved
- No attempts yet
Problem
Damir is climbing mountains. The mountain map can be represented as an grid, in which a cell at the intersection of row and column is denoted as . The height of the peak in cell is equal to a non-negative integer . Damir starts his journey on the peak in cell aiming to reach the peak in cell . If Damir is on the peak in cell , then he can go either to the peak in cell or to the peak in cell . Of course, he cannot go outside the boundaries of the map. To make the journey more interesting, he chooses the path with the largest sum of peak heights (kind of total climb).
Damir loves combinatorics, and he became curious: how many maps are there such that the sum of peak heights on his path does not exceed ? As the answer may be large, find it modulo .
Input
The only line of input contains three integers, , , and ().
Output
Print the answer modulo .