链接: http://acm.hdu.edu.cn/showproblem.php?pid=1505
没做过1506的建议先去做1506,我有详细解释
1506链接:http://blog.csdn.net/xtttgo/article/details/48085707
因为我是用1506的方法做的这题
题意:R是障碍物,求最大的F形成的矩形
实际上,我们把R的情况去掉,就是跟1506差不多的图形了
比如,题目样例
5 6
R F F F F F
F F F F F F
R R R F F F
F F F F F F
F F F F F F
化简成
5 6
0 1 1 1 1 1
1 2 2 2 2 2
0 0 0 3 3 3
1 1 1 4 4 4
2 2 2 5 5 5
如果上面一个是F,就长度+1,如果上一个是R,就为0,然后每一行都进行dp,求出每一行作为矩形的底边能形成的最大矩形面积
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<map>
#include<stack>
#include<algorithm>
using namespace std;
int a[1011][1011];
int l[1010], r[1010];
int main()
{
// freopen("D://input.txt", "r", stdin);
// freopen("D://output.txt", "w", stdout);
int T;
scanf("%d", &T);
while (T--)
{
int n, m;
scanf("%d%d", &n, &m);
memset(a, 0, sizeof(a));
int i, j, k;
for (i = 1; i <= n; i++)
{
for (j = 1; j <= m; j++)
{
char ch[2];
scanf("%s", ch);
if (ch[0] == 'R')
a[i][j] = 0;
else
a[i][j] = a[i - 1][j] + 1;
}
}
int ans = 0, h;
for (h = 1; h <= n; h++)
{
for (j = 0; j <= m + 1; j++)
{
l[j] = r[j] = 1;
}
for (i = 2; i <= m; i++)
{
if (a[h][i] == 0)
continue;
j = i;
while (j > 1 && a[h][j - 1] >= a[h][i])
{
l[i] += l[j - 1];
j = i - l[i] + 1;
}
}
ans = max(ans, a[h][m] * l[m]);
for (i = m - 1; i >= 1; i--)
{
if (a[h][i] == 0)
continue;
j = i;
while (j < n&&a[h][j + 1] >= a[h][i])
{
r[i] += r[j + 1];
j = i + r[i] - 1;
}
ans = max(ans, a[h][i] * (l[i] + r[i] - 1));
}
}
printf("%d\n", (ans * 3));
}
// printf(".6lf\n",(double)clock()/CLOCKS_PER_SEC);
return 0;
}