Maximal Rectangle
很不好想的一道题,参考:http://blog.csdn.net/doc_sgl/article/details/11832965
分为两步:把原矩阵转为直方图,再用largest rectangle求解:http://www.cnblogs.com/573177885qq/p/5537334.html
int largestRectangleArea(vector<int>& heights) {
stack<int> s;
heights.push_back();
int result=;
for(int i=;i<heights.size();)
{
if(s.empty()||heights[i]>heights[s.top()])
{
s.push(i++);
}
else
{
int tmp=s.top();
s.pop();
result=max(result,heights[tmp]*(s.empty()?i:i-s.top()-));
}
}
return result;
}
int maximalRectangle(vector<vector<char>>& matrix) {
int m=matrix.size();
int n=matrix[].size();
if(m== || n==)return ;
vector<vector<int>>dp(m,vector<int>(n,));
for(int j=;j<n;j++)
if(matrix[][j]=='')dp[][j]=;
for(int j=;j<n;j++)
{
for(int i=;i<m;i++)
{
if(matrix[i][j]=='')dp[i][j]=dp[i-][j]+;
}
}
int max_area=;
for(int i=;i<m;i++)
max_area=max(max_area,largestRectangleArea(dp[i]));
return max_area;
}
Maximal Rectangle的更多相关文章
- 85. Maximal Rectangle
85. Maximal Rectangle Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle c ...
- 求解最大矩形面积 — leetcode 85. Maximal Rectangle
之前切了道求解最大正方形的题,题解猛戳 这里.这道题 Maximal Rectangle 题意与之类似,但是解法完全不一样. 先来看这道题 Largest Rectangle in Histogram ...
- 【leetcode】Maximal Rectangle
Maximal Rectangle Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle conta ...
- [LintCode] Maximal Rectangle 最大矩形
Given a 2D boolean matrix filled with False and True, find the largest rectangle containing all True ...
- 47. Largest Rectangle in Histogram && Maximal Rectangle
Largest Rectangle in Histogram Given n non-negative integers representing the histogram's bar height ...
- leetcode Maximal Rectangle 单调栈
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4052721.html 题目链接:leetcode Maximal Rectangle 单调栈 ...
- leetcode面试准备: Maximal Rectangle
leetcode面试准备: Maximal Rectangle 1 题目 Given a 2D binary matrix filled with 0's and 1's, find the larg ...
- LeetCode之“动态规划”:Maximal Square && Largest Rectangle in Histogram && Maximal Rectangle
1. Maximal Square 题目链接 题目要求: Given a 2D binary matrix filled with 0's and 1's, find the largest squa ...
- 最大的矩形面积 Maximal Rectangle
2018-09-15 10:23:44 一.Largest Rectangle in Histogram 在求解最大的矩形面积之前,我们先讨论一条最大直方图面积的问题. 问题描述: 问题求解: 解法一 ...
- 85. Maximal Rectangle (Graph; Stack, DP)
Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and ...
随机推荐
- Linux 管道的实现模型
//管道的实现 //当前目录下实现命令"ls | wc -w" #include <stdio.h> #include <stdlib.h> #includ ...
- [LeetCode] Perfect Squares 完全平方数
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 1 ...
- 数组为什么可以使用linq查询
问题引出 这视乎是个完全不必要进行讨论的话题,因为linq(这里具体是linq to objects)本来就是针对集合类型的,数组类型作为集合类型的一种当然可以使用了.不过我还是想写一下,这个问题源于 ...
- Markdown语法
概述 Markdown的理念是能让文档更容易读.写和随 改. 它用简洁的语法代替排版,格式语法只涵盖纯文 本可以涵盖的范围. 不在 Markdown 涵盖范围之内的标签,都可以直接在文档里面用 HTM ...
- c# Using Settings under visual studio 2012
1.在项目属性中的Settings的设置可以通过以下方式调用 Properties.Settings.Default.(SpecifyPropertyName) 2.添加新的Settings设置文件 ...
- import renumber.py in pymol
cp renumber.py /usr/local/lib/python2.7/dist-packages/pymol import renumber or run /path/to/renumber ...
- 关于repaint(重绘)和reflow( 回流)
repaint就是重绘,reflow就是回流.repaint主要是针对某一个DOM元素进行的重绘,reflow则是回流,针对整个页面的重排 严重性: 在性能优先的前提下,性能消耗 reflow大于re ...
- Code Conventions for the Java
Oracel官方JAVA编码规范指引 http://www.oracle.com/technetwork/java/codeconvtoc-136057.html
- Linux下常用压缩 解压命令和压缩比率对比
常用的格式有:tar, tar.gz(tgz), tar.bz2, 不同方式,压缩和解压方式所耗CPU时间和压缩比率也差异也比较大. 1. tar只是打包动作,相当于归档处理,不做压缩:解压也一样,只 ...
- php获得远程信息到本地使用的3个函数:file_get_contents和curl函数和stream_get_contents
1:file_get_contents echo file_get_contents("http://www.php.com/index.php"); 2:curl funct ...