Farmer John's cows have invented a variant of Hopscotch. The game is played on an R by C grid (2 <= R <= 15, 2 <= C <= 15), where each square is colored either red or blue. 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 of a different color,
- 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 and C. The next R lines each contain C characters, each 'R' (red) or 'B' (blue).
Output
The number of different ways one can jump from the top-left square to the bottom-right square.
Example 1
Input
4 4 RRRR RRBR RBBR RRRR
Output
3
Discussion
Threads about this problem. Spoilers are collapsed; wrap hints in
||double bars||.No discussion yet. Start a thread if something here needs explaining.