1、1505 City Game
171MS 5996K
dp压缩的思想和左边数组和右边数组(求的时候使用循环递归的思想,不要暴力)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<string>
#define MAXNUM 1020
using namespace std;
int M, N, sum[MAXNUM][MAXNUM], l[MAXNUM], r[MAXNUM];
int main()
{
freopen("1.txt", "r", stdin);
int i, j, t, k, a, b, cases, ans, tmp;
char c;
scanf("%d", &cases);
while (cases > 0)
{
memset(sum, 0, sizeof(sum));
scanf("%d%d", &M, &N);
for (i = 1; i <= M; i++)
{
for (j = 1; j <= N; j++)
{
cin >> c;
if (c == 'R')
sum[i][j] = 0;
else
sum[i][j] = sum[i][j - 1] + 1;
}
}
ans = 0;
for (i = 1; i <= N; i++)
{
l[1] = 1;
r[M] = M;
for (j = 2; j <= M; j++)
{
l[j] = j;
while (l[j]>1&&sum[j][i] <= sum[l[j] - 1][i])
l[j] = l[l[j] - 1];
}
for (j = M - 1; j >= 1; j--)
{
r[j] = j;
while (r[j]<M&&sum[j][i] <= sum[r[j] + 1][i])
r[j] = r[r[j] + 1];
}
for (j = 1; j <= M; j++)
{
if (sum[j][i])
{
tmp = (r[j] - l[j