#P4825. Cow Hopscotch

    ID: 18069 Type: Default 1000ms 256MiB

Cow Hopscotch

Cow Hopscotch

Cows have invented their own version of hopscotch on a grid. The game is played on an \(R \times C\) grid where each cell contains an integer between \(1\) and \(K\). The cows start at the top-left cell and must reach the bottom-right cell by a sequence of jumps. A jump from cell \((r, c)\) to cell \((r', c')\) is valid if and only if:

  1. The destination cell has a different integer than the current cell.
  2. \(r' > r\) (i.e., the jump goes at least one row down).
  3. \(c' > c\) (i.e., the jump goes at least one column to the right).

Your task is to compute the number of different jump sequences that take the cows from the top-left cell to the bottom-right cell.

Note: The grid dimensions satisfy \(2 \le R \le 100\) and \(2 \le C \le 100\) and \(1 \le K \le R \times C\).

inputFormat

The first line contains three integers: \(R\), \(C\) and \(K\). Each of the next \(R\) lines contains \(C\) integers representing the grid.

For example:

2 2 4
1 2
3 4

outputFormat

Output a single integer: the number of distinct valid jump sequences from the top-left cell to the bottom-right cell.

sample

2 2 4
1 2
3 4
1