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 file 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 file 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 代码 :
 #include<cstdio>
#include<algorithm>
using namespace std;
const int maxn = 1000;
int sac[maxn][maxn];
int up[maxn][maxn],left[maxn][maxn],right[maxn][maxn];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int m,n;
scanf("%d%d",&m,&n);
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++)
{
int ch=getchar();
while(ch!='F'&&ch!='R')
ch=getchar();
sac[i][j]=ch=='F'?0:1;
}
}
int ans=0;
for(int i=0;i<m;i++){
int lo=-1,ro=n;
for(int j=0;j<n;j++){
if(sac[i][j]==1)
{
up[i][j]=left[i][j]=0;
lo=j;
}
else
{
up[i][j]=i==0?1:up[i-1][j]+1;
left[i][j]=i==0?lo+1:max(left[i-1][j],lo+1);
}
}
for(int j=n-1;j>=0;j--)
{
if(sac[i][j]==1)
{
right[i][j]=n;
ro=j;
}
else
{
right[i][j]=i==0?ro-1:min(right[i-1][j],ro-1);
ans=max(ans,up[i][j]*(right[i][j]-left[i][j]+1));
}
}
}
printf("%d\n",ans*3);
}
return 0;
}

la----3695 City Game(最大子矩阵)的更多相关文章

  1. UVa LA 3029 City Game 状态拆分,最大子矩阵O(n2) 难度:2

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  2. City Game(最大子矩阵)

    Bob is a strategy game programming specialist. In his new city building game the gaming environment ...

  3. LA 3029 City Game

    LA 3029 求最大子矩阵问题,主要考虑枚举方法,直接枚举肯定是不行的,因为一个大矩阵的子矩阵个数是指数级的,因此应该考虑先进行枚举前的扫描工作. 使用left,right,up数组分别记录从i,j ...

  4. LA 3029 - City Game (简单扫描线)

    题目链接 题意:给一个m*n的矩阵, 其中一些格子是空地(F), 其他是障碍(R).找一个全部由F 组成的面积最大的子矩阵, 输出其面积乘以3的结果. 思路:如果用枚举的方法,时间复杂度是O(m^2 ...

  5. UVaLive 3695 City Game (扫描线)

    题意:给定m*n的矩阵,有的是空地有的是墙,找出一个面积最大的子矩阵. 析:如果暴力,一定会超时的.我们可以使用扫描线,up[i][j] 表示从(i, j)向上可以到达的最高高度,left[i][j] ...

  6. LA 3695 Distant Galaxy

    给出n个点的坐标(坐标均为正数),求最多有多少点能同在一个矩形的边界上. 题解里是构造了这样的几个数组,图中表示的很明白了. 首先枚举两条水平线,然后left[i]表示竖线i左边位于水平线上的点,on ...

  7. UVa LA 3695 - Distant Galaxy 前缀和,状态拆分,动态规划 难度: 2

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  8. LA 3695 部分枚举

    运用部分枚举的思想,很明显完全枚举点的思想是不可能的.改为枚举上下边界,当确定右边界j后,对左边界i,可以有点数为on[j]+on[i]+(leftu[j]-leftu[i])+leftd[j]-le ...

  9. SWT入门-常用组件的使用(转)

    转自:http://www.cnblogs.com/kentyshang/archive/2007/08/16/858367.html swt的常用组件button ,text ,combo,list ...

随机推荐

  1. Creating Timer in Oracle D2k / Forms 6i and Displaying a Clock

    Creating Timer in Oracle D2k / Forms 6i and Displaying a Clock This is about timer in D2k An externa ...

  2. CentOs6.5中安装和配置vsftp简明教程

    一.vsftp安装篇 # 查看是否已经安装了vsftp: rpm -qa|grep vsftpd # 安装vsftpd(需要root权限)yum -y install vsftpd# 启动vsftpd ...

  3. C#正则表达式编程(二):Regex类用法

    上一篇讲述了在C#中有关正则表达式的类之间的关系,以及它们的方法,这一篇主要是将Regex这个类的用法的,关于Match及MatchCollection类会在下一篇讲到.对于正则表达式的应用,基本上可 ...

  4. 超实用压力测试工具-ab工具

    在学习ab工具之前,我们需了解几个关于压力测试的概念 吞吐率(Requests per second)概念:服务器并发处理能力的量化描述,单位是reqs/s,指的是某个并发用户数下单位时间内处理的请求 ...

  5. MyEclipse JCO tomcat 提示查找不到sapjco3.dll

    java.lang.UnsatisfiedLinkError: no sapjco3 in java.library.path 1.system32添加sapjco3.dll 2.tomcat bin ...

  6. Android linearlayout常用布局

    用linearlayout完成这样的布局效果,这样的布局还是比较常用的,具体的xml代码如下: <LinearLayout xmlns:android="http://schemas. ...

  7. python下载地址

    https://www.python.org/downloads/release/python-351/

  8. 杨辉三角 && 鸽兔同校

    杨辉三角: 用个一维数组直接模拟就行,只是 C++ 的高精度调了好久,后来发现能用 python ,于是试着写了写: dp = [] def out(L, end): for i in range(e ...

  9. 【官方方法】xcode7免证书真机调试

    [官方方法]xcode7免证书真机调试 步骤比较简单,我就简单总结一下. 1. 进入xcode,菜单栏选择xcode –> preferences (快捷键 command + ,)在Accou ...

  10. Winform_播放声音文件

    1.调用非托管的dll using System.Runtime.InteropServices;  //DllImport命名空间的引用 class test  //提示音 { [DllImport ...