原题地址:http://codeforces.com/gym/101652/attachments
参考博客:https://blog.csdn.net/Shili_Xu/article/details/79701749
#include
#define eps 1e-8
#define INF 0x3f3f3f3f
#define PI acos(-1)
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define CLR(x,y) memset((x),y,sizeof(x))
#define fuck(x) cerr << #x << "=" << x << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int seed = 131;
const int maxn = 1e5 + 5;
const int mod = 998244353;
int n, m;
int can[100][100];//表示一个格子是否能填B
char a[100][100];
ll dp[100][100];//dp[i][j]表示第i行,前j个都是B的方案数
bool check(int x, int y) {
for (int i = 1; i <= y; i++) {//因为dp的时候是从左向右的,所以只要判断横向可行不可行就行了
if (a[x][i] == 'R') return 0;
}
for (int i = y + 1; i <= m; i++) {
if (a[x][i] == 'B') return 0;
}
return 1;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)scanf("%s", a[i] + 1);
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= m; j++) {
can[i][j] = check(i, j);
}
}
for (int i = 0; i <= m; i++) dp[1][i] = can[1][i];//初始化
for (int i = 2; i <= n; i++) {
for (int j = 0; j <= m; j++) {
for (int k = j; k <= m; k++) {
dp[i][j] += dp[i - 1][k] * can[i][j];
}
}
}
ll ans = 0;
for (int i = 0; i <= m; i++) ans += dp[n][i];
printf("%I64d\n", ans);
return 0;
}