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. 利用jsoup爬取百度网盘资源分享连接(多线程)

    突然有一天就想说能不能用某种方法把百度网盘上分享的资源连接抓取下来,于是就动手了.知乎上有人说过最好的方法就是http://pan.baidu.com/wap抓取,一看果然链接后面的uk值是一串数字, ...

  2. Linux下的下载工具介绍----aria2

    ariac 项目地址:http://aria2.sourceforge.net/ 下载地址:http://sourceforge.net/projects/aria2/files/stable/ari ...

  3. 大爱jQuery,10美女模特有用jQuery/CSS3插入(集成点免费下载)

    整合下载地址:http://download.csdn.net/detail/yangwei19680827/7343001 jQuery真的是一款非常犀利的Javascript框架,利用jQuery ...

  4. HDU1163 Eddy&#39;s digital Roots【九剩余定理】

    Eddy's digital Roots Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  5. Mvc后台接收 参数

    @Html.TextAreaFor(m => m.Emps, new { @class = "easyui-validatebox", @style = "heig ...

  6. Android Studio怎样安装插件

    Android Studio安装插件的方式事实上和Eclipse大同小异.废话不多说,直接上图: 区域1:你当前已经安装了的插件 区域2:在线安装 区域3:从硬盘安装,即针对你已经下载好了的插件,可通 ...

  7. ContentProvider的使用

    这方面的资料应该网上已经很多了,我在这里只是做简单的总结就行了. 如题:ContentProvider是android的内容提供器,可以为应用程序提供各种的数据,例如数据表,txt文件,xml文件等等 ...

  8. 文章3说话 微信商城云server创建后台

    一个.   应用server资源              想要进行微信开发.少不了后台server端程序的开发,那么我们首先就要申请server资源.眼下有非常多云server可选,比方新浪的sae ...

  9. DiskFileUpload类别

    1.2.2 DiskFileUpload类 DiskFileUpload类是Apache文件上传组件的核心类,应用程序开发者通过这个类来与Apache文件上传组件进行交互.以下介绍DiskFileUp ...

  10. [LeetCode]Word Ladder 最短距离字符串转换 (Dijkstra)

    要求最短距离.采纳dijkstra查找节点之间的最短路径. 当心:假设是一个枚举字典22是否元素可以,如果转换,暂停. 提高:每串,带您历数它的字符值事件,对于的长度n一个字符串枚举n*26次要. 设 ...