Farmer John's cows play a variant of Hopscotch on an R by C grid (2 <= R <= 100, 2 <= C <= 100), where each square is labeled with an integer in the range 1..K (1 <= K <= R*C). Cows start in the top-left square and move to the bottom-right square by a sequence of jumps, where a jump is valid if and only if:
- You are jumping to a square labeled with a different integer than your current square,
- The square you are jumping to is at least one row below the current square, and
- The square you are jumping to is at least one column to the right of the current square.
Please help the cows compute the number of different possible sequences of valid jumps from the top-left square to the bottom-right square.
Input
Line 1: R, C, and K. The next R lines each contain C integers, each in the range 1..K.
Output
The number of different ways one can jump from the top-left square to the bottom-right square, mod 1000000007.
Example 1
4 4 4 1 1 1 1 1 3 2 1 1 2 4 1 1 1 1 1
5
Discussion
Threads about this problem. Spoilers are collapsed; wrap hints in
||double bars||.No discussion yet. Start a thread if something here needs explaining.