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 �C 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.

InputThe first line of the input contains an integer K �C 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 �C reserved unit

F �C free unit

In the end of each area description there is a separating line. 
OutputFor 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 // 题意:第一行测试组数T,然后 n ,m 代表矩阵大小 n行m列 ,只有 F 才能建,求最大子矩阵
有点复杂,但是,如果你做过 hdu1506 ,这题一下就想到了。
对于每行都建个 L[] , R[] 数组,
 #include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define MX 1005
int n,m;
int h[MX][MX];
int L[MX][MX];
int R[MX][MX];
char mp[MX][MX]; void set_h()
{
memset(h,,sizeof(h));
for (int i=;i<=m;i++)
if (mp[][i]=='F')
h[][i]=;
for (int i=;i<=n;i++)
for (int j=;j<=m;j++)
if (mp[i][j]=='F')
h[i][j]=h[i-][j]+;
} void set_LR()
{
for (int i=;i<=n;i++)
{
for (int j=;j<=m;j++)
{
L[i][j]=j;
if (h[i][j]==) continue;
while (h[i][L[i][j]-]>=h[i][j])
L[i][j]=L[i][L[i][j]-];
}
}
for (int i=;i<=n;i++)
{
for (int j=m;j>=;j--)
{
R[i][j]=j;
if (h[i][j]==) continue;
while (h[i][R[i][j]+]>=h[i][j])
R[i][j]=R[i][R[i][j]+];
}
}
} int main()
{
int t;
cin>>t;
while (t--)
{
scanf("%d%d",&n,&m);
for (int i=;i<=n;i++)
{
for (int j=;j<=m;j++)
{
char sss[];
scanf("%s",sss);
mp[i][j]=sss[];
}
}
set_h();
set_LR();
int ans = ;
for (int i=;i<=n;i++)
{
for (int j=;j<=m;j++)
{
int area = (R[i][j]-L[i][j]+)*h[i][j];
if (area>ans) ans = area;
}
}
printf("%d\n",ans*);
}
return ;
}
 

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

  1. la----3695 City Game(最大子矩阵)

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

  2. DP:0

    小故事: A * "1+1+1+1+1+1+1+1 =?" * A : "上面等式的值是多少" B : *计算* "8!" A *在上面等式 ...

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

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

  4. POJ 1964&HDU 1505&HOJ 1644 City Game(最大0,1子矩阵和总结)

    最大01子矩阵和,就是一个矩阵的元素不是0就是1,然后求最大的子矩阵,子矩阵里的元素都是相同的. 这个题目,三个oj有不同的要求,hoj的要求是5s,poj是3秒,hdu是1秒.不同的要求就对应不同的 ...

  5. City Game UVALive - 3029(悬线法求最大子矩阵)

    题意:多组数据(国外题好像都这样),每次n*m矩形,F表示空地,R表示障碍 求最大子矩阵(悬线法模板) 把每个格子向上延伸的空格看做一条悬线 以le[i][j],re[i][j],up[i][j]分别 ...

  6. 十月例题F题 - City Game

    F - City Game Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Bob is a st ...

  7. 【巧妙预处理系列】【UVA1330】City game

    最大子矩阵(City Game, SEERC 2004, LA 3029) 给定一个m×n的矩阵,其中一些格子是空地(F),其他是障碍(R).找出一个全部由F组成的面积最大的子矩阵,输出其面积乘以3后 ...

  8. hdu 1505(最大子矩阵)

    City Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total S ...

  9. ACM 中 矩阵数据的预处理 && 求子矩阵元素和问题

            我们考虑一个$N\times M$的矩阵数据,若要对矩阵中的部分数据进行读取,比如求某个$a\times b$的子矩阵的元素和,通常我们可以想到$O(ab)$的遍历那个子矩阵,对它的各 ...

随机推荐

  1. adb 设备不识别

    android真坑 有两台测试机 都能连能snapdragon profiling了 忽然 一台不能识别了 adb devices 就不存在 一台一直是好的 kill server start ser ...

  2. 使用ffmpeg截取视频封面并批量上传

    需求:将视频文件压入zip包,然后上传服务器.服务器对zip解压,使用bat/shell,使用ffmpeg对视频进行封面截取.再使用OSS对视频和封面进行批量上传.最后将信息存入数据库 遇到的问题 1 ...

  3. 使用Kinect2作为Oculus游戏应用的输入设备

    注: 文章写于2015年8月, 眼下VR游戏Demo已经完结, 所以把上一次预研的一些经验分享出来, 希望对大家有所帮助 背景 初接触Oculus时, 从网上下载了一大堆的Demo来体验, 可是, 操 ...

  4. IDEA如何打包可运行jar的一个问题

    转载:http://bglmmz.iteye.com/blog/2058785 背景: 有时候,我们会用IDEA来开发一些小工具,需要打成可运行的JAR包:或者某些项目不是WEB应用,纯粹是后台应用, ...

  5. IO流(二)I/O

    一.IO流概述 1.定义:Java的IO流是实现输入输出的基础,它可以方便地实现数据的输入/输出操作. 2.流的分类: (1)按流向来分:输入流和输出流 (2)按操作的数据来分:字节流和字符流 (3) ...

  6. Android学习(三) 自动完成的使用

    1.AutoCompleteTextView 自动完成功能,在文本框中输入字符,会出现匹配的自动提示.类似百度搜索. XML代码 <?xml version="1.0" en ...

  7. Spring IOC源代码具体解释之容器初始化

    Spring IOC源代码具体解释之容器初始化 上篇介绍了Spring IOC的大致体系类图,先来看一段简短的代码,使用IOC比較典型的代码 ClassPathResource res = new C ...

  8. linux 命令笔记: iptables

    配置虚拟机网卡 NAT 联网: iptables -t nat -A POSTROUTING -s 192.168.0.0/16 -j MASQUERADE iptables -A FROWARD - ...

  9. nightwatch API

    API Nightwatch的API分为四个部分 1.Expect 在browser实例上以.expect.element开头的BDD(行为驱动测试)风格的接口,0.7及以上版本nightwatch可 ...

  10. 改变listview中item选中时文字的颜色

    摘要 当listview的某个item选中时,默认有个选中的高亮显示,如果你要自定义选中时的高亮显示效果,可以在listview中设置属性 android:listSelector="@dr ...