Cow Hopscotch
Time limit1sMemory limit256 MB
Count paths from the top-left to the bottom-right cell that step strictly down and right onto a different value, modulo 1000000007.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Prefix sum, Matrix
- Solved
- No attempts yet
Problem
People enjoy playing hopscotch, and Farmer John's cows have invented a variant for themselves. Clumsy animals weighing nearly a ton play it, so cow hopscotch almost always ends in disaster. The cows still set the board up nearly every afternoon.
The board is an grid (, ). Each square holds one integer between and (). A cow starts on the top-left square and reaches the bottom-right square with a sequence of jumps. A jump is valid only when all three of these conditions hold.
- The integer on the destination square differs from the integer on the current square.
- The destination square is at least one row below the current square.
- The destination square is at least one column to the right of the current square.
Count the different sequences of valid jumps that take a cow from the top-left square to the bottom-right square.
Input
The first line contains the integers , , and .
Each of the next lines contains integers. All of them are between and .
Output
Print on one line the number of different ways to get from the top-left square to the bottom-right square, modulo .