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. 【转载】UML类图知识整理

    原文:UML类图知识整理 UML类图 UML,进阶必备专业技能,看不懂UML就会看不懂那些优秀的资料. 这里简单整理 类之间的关系 泛化关系(generalization) 泛化(generalize ...

  2. iOS案例:读取指定目录下的文件列表

    // // main.m // 读取指定目录下的文件列表 // // Created by Apple on 15/11/24. // Copyright © 2015年 Apple. All rig ...

  3. MVC 3 数据验证 Model Validation 详解

    在MVC 3中 数据验证,已经应用的非常普遍,我们在web form时代需要在View端通过js来验证每个需要验证的控件值,并且这种验证的可用性很低.但是来到了MVC 新时代,我们可以通过MVC提供的 ...

  4. iOS - Swift Set 集合

    前言 Set:集合 public struct Set<Element : Hashable> : Hashable, CollectionType, ArrayLiteralConver ...

  5. Nginx基础知识之————Nginx 环境的搭建?

    本课时主要给大家讲解如何在 Linux 系统下搭建 Nginx 和 Nginx 搭建过程中常见问题的知识,并结合实例让学员掌握 Nginx 环境的搭建. 下载解压: 安装gcc-c++ 从新配置文件: ...

  6. JSP Filter,GZIP压缩响应流

    url:http://hi.baidu.com/xhftx/blog/item/fbc11d3012648711ebc4af59.html 关键词:JSP,Filter,Servlet,GZIP 现在 ...

  7. [转载] HTTP请求的TCP瓶颈分析

    原文: http://bhsc881114.github.io/2015/06/23/HTTP%E8%AF%B7%E6%B1%82%E7%9A%84TCP%E7%93%B6%E9%A2%88%E5%8 ...

  8. poj3384Feng Shui(半平面交)

    链接 将边长向内推进r,明显这样把第一个圆的圆心放在新的边长是肯定是最优的,与原本边相切,然后再找新多边上的最远的两点即为两圆心. #include <iostream> #include ...

  9. (一)stm32之CMSIS标准、库目录、GPIO

    一.CMSIS标准 ST公司的stm32采用的是cortex-m3内核,内核是整个微处理器的CPU.该内核是ARM公司设计的一种处理器体系架构.内核与外设的关系就像PC上的CPU与硬盘.主板.内存等的 ...

  10. Git的优势

    分布式,强调个体 公共服务器压力和数据量都不会太大 速度快.灵活 任意两个开发者之间可以很容易的解决冲突 离线工作