题目

Description

Bob is a strategy game programming specialist. In his new city building game the gaming environment is as follows: a city is built up by areas, in which there are streets, trees,factories and buildings. There is still some space in the area that is unoccupied. The strategic task of his game is to win as much rent money from these free spaces. To win rent money you must erect buildings, that can only be rectangular, as long and wide as you can. Bob is trying to find a way to build the biggest possible building in each area. But he comes across some problems – he is not allowed to destroy already existing buildings, trees, factories and streets in the area he is building in.

Each area has its width and length. The area is divided into a grid of equal square units.The rent paid for each unit on which you're building stands is 3$.

Your task is to help Bob solve this problem. The whole city is divided into K areas. Each one of the areas is rectangular and has a different grid size with its own length M and width N.The existing occupied units are marked with the symbol R. The unoccupied units are marked with the symbol F.

Input

The first line of the input contains an integer K – determining the number of datasets. Next lines contain the area descriptions. One description is defined in the following way: The first line contains two integers-area length M<=1000 and width N<=1000, separated by a blank space. The next M lines contain N symbols that mark the reserved or free grid units,separated by a blank space. The symbols used are:

R – reserved unit

F – free unit

In the end of each area description there is a separating line.

Output

For each data set in the input print on a separate line, on the standard output, the integer that represents the profit obtained by erecting the largest building in the area encoded by the data set.

Sample Input

2
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 5
R R R R R
R R R R R
R R R R R
R R R R R
R R R R R

Sample Output

45
0

翻译

描述

Bob 是一个战略游戏制作人.在他新的城市建设游戏中,游戏设定如下:
城市按照包括街道、树木、工厂、建筑的区域建设,同时有部分空闲的区域
战略目标是从空闲地域赢取尽可能多的钱
为了获得租金,你需要尽可能大地建筑长方形的房屋区域.
Bob在尝试寻求一个能够在每个区域能尽可能多建的方案
但是他遇到了困难——他不能摧毁已经建好的区域

每个区域有宽度和高度,区域被分成多个相同的正方形单元,每个单元的租金为3$

你的任务是帮助Bob解决这个问题.整个城市分成 K 个区域.每一个区域都是长方形的并且面积不同
已经有建筑的区域标记为 R ,未建筑的区域标记为 F

输入

第一行包括一个整数 K 表示区域的数目
接下来的区域进行描述
每个区域由 MN 开始,分别代表区域的宽和高( M、N <= 1000 )
接下来 M 行每行有 N 个字符,用符号:
R - 已使用区域
F - 空闲区域
每个区域结尾有一个空行

输出

对于每组数据将能够赚取的最多的钱数输出在一行中

题解

在一块区域内求取最大矩形
>HDU 1506.Largest Rectangle in a Histogram< 类似

以每一层为基线运算上面的题即可

多计算一个高度即可

最后的最大面积要 *3

代码

/*
By:OhYee
Github:OhYee
Blog:http://www.oyohyee.com/
Email:oyohyee@oyohyee.com

かしこいかわいい?
エリーチカ!
要写出来Хорошо的代码哦~
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <functional>
using namespace std;

const int maxn = 1005;
bool Map[maxn][maxn];

int H[maxn][maxn];
int Left[maxn][maxn];
int Right[maxn][maxn];

//int S[maxn][maxn];

void Do() {
    int n,m;
    scanf("%d%d",&n,&m);
    memset(Map,0,sizeof(Map));
    memset(H,0,sizeof(H));
    memset(Left,0,sizeof(Left));
    memset(Right,0,sizeof(Right));

    for(int i = 1;i <= n;i++)
        for(int j = 1;j <= m;j++) {
            char temp;
            scanf("\n%c",&temp);
            if(temp == 'R')
                Map[i][j] = false;
            else
                Map[i][j] = true;
        }


    for(int i = 1;i <= n;i++)
        for(int j = 1;j <= m;j++) {
            if(Map[i][j]) {
                if(Map[i - 1][j])
                    H[i][j] = H[i - 1][j] + 1;
                else
                    H[i][j] = 1;
            }
        }

    for(int i = 1;i <= n;i++)
        for(int j = 1;j <= m;j++) {
            if(Map[i][j]) {
                int t = j;
                while(t >= 1 && H[i][j] <= H[i][t - 1])
                    t = Left[i][t - 1];
                Left[i][j] = t;
            }
        }

    for(int i = 1;i <= n;i++)
        for(int j = m;j >= 1;j--) {
            if(Map[i][j]) {
                int t = j;
                while(t <= m && H[i][j] <= H[i][t + 1])
                    t = Right[i][t + 1];
                Right[i][j] = t;
            }
        }

    int Max = 0;
    for(int i = 1;i <= n;i++)
        for(int j = 1;j <= m;j++) {
            if(Map[i][j]) {
                int S = H[i][j]*(Right[i][j] - Left[i][j] + 1);
                Max = max(Max,S);
            }
        }


    printf("%d\n",Max*3);
}


int main() {
    int T;
    scanf("%d",&T);
    while(T--)
        Do();
    return 0;
}