Problem list
Log in
#usaco0178 · USACO 2014-2015 February Bronze

Cow Hopscotch (Bronze)

Silver II 2.0 s 256 MB

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:

  1. You are jumping to a square of a different color,
  2. The square you are jumping to is at least one row below the current square, and
  3. 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
Source
USACO 2014-2015 February Bronze
Appears in
Not part of a ladder, contest or set yet.
Accepted 0 Submissions 0 Acceptance 0% Solvers 0

Discussion

Threads about this problem. Spoilers are collapsed; wrap hints in ||double bars||.

No discussion yet. Start a thread if something here needs explaining.

Recent submissions Open with filters
Code