[USACO2015February,Bronze] Problem3.Cow Hopscotch(Bronze)

Just like humans enjoy playing the game of Hopscotch, Farmer John’s cows have invented a variant of the game for themselves to play. Being played by clumsy animals weighing nearly a ton, Cow Hopscotch almost always ends in disaster, but this has surprisingly not deterred the cows from attempting to play nearly every afternoon.

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 that you are jumping to is at least one row below the current square that you are on, and
  3. The square that you are jumping to is at least one column to the right of the current square that you are on.

Please help the cows compute the number of different possible sequences of valid jumps that will take them from the top-left square to the bottom-right square.

INPUT FORMAT: (file hopscotch.in)

The first line contains the two integers R and C. The next R lines will each contain C characters. Each character is either ‘R’ or a ‘B’, indicating a red square or a blue square.

OUTPUT FORMAT: (file hopscotch.out)

Output the number of different ways one can jump from the top-left square to the bottom-right square.

SAMPLE INPUT:
4 4
RRRR
RRBR
RBBR
RRRR
SAMPLE OUTPUT:
3

[Problem credits: Nick Wu, 2015]

这个数据范围这么小,没什么好说的,直接暴搜就可以了.

我的代码:(MarkDown的代码片真难看)

#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
const int maxn = 20;
string Map[maxn];
int R, C;
int count(int x, int y)
{
  if(x == R - 1 && y == C - 1)
    return 1;
  int ret = 0;
  for(int i = x + 1; i < R; i++)
    for(int j = y + 1; j < C; j++)
      if(Map[x][y] != Map[i][j])
        ret += count(i, j);
  return ret;
}
int main()
{
  freopen("hopscotch.in", "r", stdin);
  freopen("hopscotch.out", "w", stdout);
  cin >> R >> C;
  for(int i = 0; i < R; i++)
    cin >> Map[i];
  cout << count(0, 0) << endl;
  return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值