题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1505

City Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6195    Accepted Submission(s): 2640

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
 
做了1506后来看的这道加强版,虽然之前知道此题为1506的加强版,但还是没有想出做法,看了题解自己默写出来的。
此题为hdu1506的加强版,1506是给定一维上的高度求其中的最大的矩形,该题为给出矩阵求其中的的最大的矩形(有些单元有障碍),该题可转化为1506,只是多了一个维度,即对每一行都进行1506中的动态规划。为加深印象,在写一遍1506的思想,从左往右遍历i,找到i的左边界(只要左边的(t-1)的高度大于等于i的高度,即a[t-1][j]>=a[j][i],那么i的左边界就可以向左延伸),注意限制i(i>1),是为了避免边上的高度为0而循环无法结束而超时;右边界同理,最后再计算(r[j]-l[j]+1)*a[j][i],取所有中最大的。
在这之前还需要构造a[][]这个数组,详细见代码。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std; char map[][];
int a[][];
int main()
{
int l[],r[];
int t,m,n;
char ch;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&m,&n);
for(int i=; i<=m; i++)
for(int j=; j<=n; j++)
cin>>map[i][j];
for(int i=; i<=m; i++)
for(int j=; j<=n; j++)
{
if(map[i][j]=='F')
a[j][i]=a[j][i-]+;
else
a[j][i]=;
}
int maxn=;
for(int i=; i<=m; i++)
{
l[]=;
r[n]=n;
for(int j=; j<=n; j++)
{
int tt=j;
while(a[tt-][i]>=a[j][i]&&tt>)
tt=l[tt-];
l[j]=tt;
}
for(int j=n-;j>=;j--)
{
int tt=j;
while(a[tt+][i]>=a[j][i]&&tt<n)
tt=r[tt+];
r[j]=tt;
}
for(int j=;j<=n;j++)
if(maxn<(r[j]-l[j]+)*a[j][i])
maxn=(r[j]-l[j]+)*a[j][i];
}
printf("%d\n",maxn*);
}
return ;
}

HDU_1505_矩阵中的最大矩形_dp的更多相关文章

  1. 84. Largest Rectangle in Histogram *HARD* -- 柱状图求最大面积 85. Maximal Rectangle *HARD* -- 求01矩阵中的最大矩形

    1. Given n non-negative integers representing the histogram's bar height where the width of each bar ...

  2. hdu1506 直方图中最大的矩形 单调栈入门

    hdu1506 直方图中最大的矩形 单调栈入门 直方图是由在公共基线对齐的矩形序列组成的多边形.矩形具有相同的宽度,但可能具有不同的高度.例如,左侧的数字显示了由高度为2,1,4,5,1,3,3的矩形 ...

  3. 19牛客暑期多校 round2 H 01矩阵内第二大矩形

    题目传送门//res tp nowcoder 目的 给定n*m 01矩阵,求矩阵内第二大矩形 分析 O(nm)预处理01矩阵为n个直方图,问题转换为求n个直方图中的第二大矩形.单调栈计算,同时维护前二 ...

  4. [LeetCode] Kth Smallest Element in a Sorted Matrix 有序矩阵中第K小的元素

    Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth ...

  5. [LeetCode] Longest Increasing Path in a Matrix 矩阵中的最长递增路径

    Given an integer matrix, find the length of the longest increasing path. From each cell, you can eit ...

  6. [LeetCode] Largest Rectangle in Histogram 直方图中最大的矩形

    Given n non-negative integers representing the histogram's bar height where the width of each bar is ...

  7. 杨氏矩阵:查找x是否在矩阵中,第K大数

    参考:http://xudacheng06.blog.163.com/blog/static/4894143320127891610158/ 杨氏矩阵(Young Tableau)是一个很奇妙的数据结 ...

  8. 一个N*M的矩阵,找出这个矩阵中所有元素的和不小于K的面积最小的子矩阵

    题目描述: 一个N*M的矩阵,找出这个矩阵中所有元素的和不小于K的面积最小的子矩阵(矩阵中元素个数为矩阵面积) 输入: 每个案例第一行三个正整数N,M<=100,表示矩阵大小,和一个整数K 接下 ...

  9. 如何在html中做圆角矩形和 只有右边的"分隔线"

    这个网站满好的,可以常看看 css-matic中有几个很好的写css可视化的工具 其实做css 版式布局等都可以有工具的 推荐40个优秀的免费CSS工具 debugger正则表达式在线 其实是对(理论 ...

随机推荐

  1. node-V8

    Node是基于V8引擎的,所以我们运行Js文件不会存在问题,下面演示一下: 因为安装Vscode后,会自动添加本路径到path,所以可以用 code yes.js 来执行创建文件 Vscode是基于N ...

  2. yarn之安装依赖包

    安装依赖关系 yarn install用于安装项目的所有依赖项.依赖关系从您的项目package.json文件中检索,并存储在yarn.lock文件中. 开发包时,安装依赖关系最常见的是在 您刚刚检出 ...

  3. Android 圆形/圆角图片的方法

    Android 圆形/圆角图片的方法 眼下网上有非常多圆角图片的实例,Github上也有一些成熟的项目.之前做项目,为了稳定高效都是选用Github上的项目直接用.但这样的结束也是Android开发必 ...

  4. vSphere,ESXi,vCenter之间的关系

    vSphere是什么? vSphere 是VMware公司公布的一整套产品包,包括类似于VMware ESXi hypervisor.VMware vCenter Server等产品 ESXi是什么? ...

  5. onenstack 简介

    一.云计算的前世今生 所有的新事物都不是突然冒出来的,都有前世和今生.云计算也是IT技术不断发展的产物. 要理解云计算,需要对IT系统架构的发展过程有所认识. 请看下 IT系统架构的发展到目前为止大致 ...

  6. redis 事务 及发布于订阅功能

    事务: Redis事务可以一次执行多个命令,事务具有以下特征: 1.隔离操作:事务中的所有命令都会序列化.按顺序地执行,不会被其他命令打扰. 2.原子操作:事务中的命令要么全部被执行,要么全部都不执行 ...

  7. Tomcat 隐藏Server Name

    隐藏Http请求中的Header ServerName 方法一 在tomcat/lib/tomcat-coyote.jar中 下面两个文件 org/apache/coyote/http11/Const ...

  8. Python爬虫开发【第1篇】【Requests】

    1.安装 利用 pip 安装 或者利用 easy_install 都可以完成安装: pip install requests easy_install requests 2.基本GET请求(heade ...

  9. Scala界面事件处理

    演示样例代码: import scala.swing.SimpleSwingApplication import scala.swing.MainFrame import scala.swing.Bu ...

  10. oss

    import oss2 ''' auth = oss2.Auth('您的AccessKeyId', '您的AccessKeySecret') bucket = oss2.Bucket(auth, '您 ...