Problem 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
 
Source
 
Recommend
zl   |   We have carefully selected several similar problems for you:  1069 

pid=1176" target="_blank">1176 1864 

pid=1003" target="_blank">1003 

pid=2571" target="_blank">2571 

 

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
using namespace std; #define N 1005 int h[N][N],le[N],ri[N];
int n,m; int main()
{
int i,t,j;
scanf("%d",&t);
while(t--)
{ memset(h,0,sizeof(h)) ;
scanf("%d%d",&n,&m);
char c;
int ans=0; for(i=1;i<=n;i++)
for(j=1;j<=m;j++)
{ cin>>c;
if(c=='F')
h[i][j]=h[i-1][j]+1;
else
h[i][j]=0;
} for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
le[j]=j;
while(le[j]>1&&h[i][le[j]]<=h[i][le[j]-1])
le[j]=le[le[j]-1];
} for(j=m;j>=1;j--)
{
ri[j]=j;
while(ri[j]<m&&h[i][ri[j]]<=h[i][ri[j]+1])
ri[j]=ri[ri[j]+1];
} for(j=1;j<=m;j++)
ans=max(ans,h[i][j]*(ri[j]-le[j]+1));
} printf("%d\n",ans*3);
}
return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

HDU 1505 City Game(01矩阵 dp)的更多相关文章

  1. HDU 1505 City Game (hdu1506 dp二维加强版)

    F - City Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi ...

  2. HDU 1505 City Game(DP)

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

  3. HDU 1505 City Game【DP】

    题意:是二维的1506,即在1506的基础上,再加一个for循环,即从第一行到最后一行再扫一遍--- 自己写的时候,输入的方法不对---发现输不出结果,后来看了别人的----@_@发现是将字母和空格当 ...

  4. HDU 6155 Subsequence Count(矩阵 + DP + 线段树)题解

    题意:01串,操作1:把l r区间的0变1,1变0:操作2:求出l r区间的子序列种数 思路:设DP[i][j]为到i为止以j结尾的种数,假设j为0,那么dp[i][0] = dp[i - 1][1] ...

  5. HDU 2602 Bone Collector (01背包DP)

    题意:给定一个体积,和一些物品的价值和体积,问你最大的价值. 析:最基础的01背包,dp[i] 表示体积 i 时最大价值. 代码如下: #pragma comment(linker, "/S ...

  6. HDU 1505 City Game

    这题是上一题的升级版 关键在于条形图的构造,逐行处理输入的矩阵,遇到'F'则在上一次的条形图基础上再加1,遇到'R'则置为0 然后用上一题的算法,求每行对应条形图的最大矩阵的面积. 另外:本来是deb ...

  7. hdu 1505 City Game (hdu1506加强版)

    # include <stdio.h> # include <algorithm> # include <string.h> # include <iostr ...

  8. hdu 4975 最大流问题解决队伍和矩阵,利用矩阵dp优化

    //刚開始乱搞. //网络流求解,假设最大流=全部元素的和则有解:利用残留网络推断是否唯一, //方法有两种,第一种是深搜看看是否存在正边权的环.见上一篇4888 //至少四个点构成的环,另外一种是用 ...

  9. hdu 4975 最大流解决行列和求矩阵问题,用到矩阵dp优化

    //刚开始乱搞. //网络流求解,如果最大流=所有元素的和则有解:利用残留网络判断是否唯一, //方法有两种,第一种是深搜看看是否存在正边权的环,见上一篇4888 //至少四个点构成的环,第二种是用矩 ...

随机推荐

  1. Emacs经常使用快捷键的注意事项

    一直用VIM,尝试了好几次Emacs都被它"多得像天上的星星"一样的快捷键给吓倒了.这几天最终下定决心再次尝试. 将它的Tutor练习了一下,顺便对经常使用快捷键做了一下笔记,方便 ...

  2. C#获取FTP文件详细备注信息

    private void button1_Click(object sender, RoutedEventArgs e) { Uri uri = new Uri("ftp://192.168 ...

  3. (视频)《高速创建站点》 4.2 完结篇 – 应用运营vs.发射卫星,遥測(Telemetry) 技术

    本文是<高速创建站点>系列的第10篇(完结篇),假设你还没有看过之前的内容,建议你点击下面文件夹中的章节先阅读其它内容再回到本文.訪问本系列文件夹.请点击:http://anb.io/bl ...

  4. ByteBuffer的allocate和allocateDirect

    在Java中当我们要对数据进行更底层的操作时,一般是操作数据的字节(byte)形式,这时经常会用到ByteBuffer这样一个类.ByteBuffer提供了两种静态实例方式: public stati ...

  5. 再见,CSDN

    这是第三次的博客, 首先是从百度改变自己 从他的变化二CSDN 看看多年的积累, 真的不想,但CSDN搜电缆和编辑(新MarkDown更烂)实在不敢恭维 再见CSDN, 新的博客 http://my. ...

  6. EXCEL随机密码生成函数

    =CHAR(INT(RAND()*+))&INT(RAND()*+)&CHAR(INT(RAND()*+))&INT(RAND()*+)&CHAR(INT(RAND() ...

  7. 利用ffmpeg将H264解码为RGB

    因为公司买到了一个不提供解码器的设备,我不得已还要做解码的工作.在网上找了一圈,H264解码比較方便的也就是ffmpeg一系列的函数库了,原本设备中也是用这套函数库解码,但厂家不给提供,没办法,仅仅得 ...

  8. 【翻译mos文章】Linux x86 and x86-64 系统SHMMAX最大

    Linux x86 and x86-64 系统SHMMAX最大值 参考原始: Maximum SHMMAX values for Linux x86 and x86-64 (文件 ID 567506. ...

  9. js右侧悬浮框

    示例:屏幕右侧悬浮框 原理:oDiv.style.top = document.documentElement.clientHeight - oDiv.offsetHeight + scrollTop ...

  10. 返璞归真 asp.net mvc (8) - asp.net mvc 3.0 新特性之 Model

    原文:返璞归真 asp.net mvc (8) - asp.net mvc 3.0 新特性之 Model [索引页][源码下载] 返璞归真 asp.net mvc (8) - asp.net mvc ...