很不好想的一道题,参考: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的更多相关文章

  1. 85. Maximal Rectangle

    85. Maximal Rectangle Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle c ...

  2. 求解最大矩形面积 — leetcode 85. Maximal Rectangle

    之前切了道求解最大正方形的题,题解猛戳 这里.这道题 Maximal Rectangle 题意与之类似,但是解法完全不一样. 先来看这道题 Largest Rectangle in Histogram ...

  3. 【leetcode】Maximal Rectangle

    Maximal Rectangle Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle conta ...

  4. [LintCode] Maximal Rectangle 最大矩形

    Given a 2D boolean matrix filled with False and True, find the largest rectangle containing all True ...

  5. 47. Largest Rectangle in Histogram && Maximal Rectangle

    Largest Rectangle in Histogram Given n non-negative integers representing the histogram's bar height ...

  6. leetcode Maximal Rectangle 单调栈

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4052721.html 题目链接:leetcode Maximal Rectangle 单调栈 ...

  7. leetcode面试准备: Maximal Rectangle

    leetcode面试准备: Maximal Rectangle 1 题目 Given a 2D binary matrix filled with 0's and 1's, find the larg ...

  8. 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 ...

  9. 最大的矩形面积 Maximal Rectangle

    2018-09-15 10:23:44 一.Largest Rectangle in Histogram 在求解最大的矩形面积之前,我们先讨论一条最大直方图面积的问题. 问题描述: 问题求解: 解法一 ...

  10. 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 ...

随机推荐

  1. Maven打包含有Main方法jar并运行

    最近使用Kettle做定时数据抽取,因为Job更新或需求变更,修改Bug等种种原因,需要对重跑Job一般是针对每天的数据重跑一次.刚开始的做法是直接在自己的开发机器上重跑,这样速度比较慢,因为这时候你 ...

  2. [LeetCode] Maximum Size Subarray Sum Equals k 最大子数组之和为k

    Given an array nums and a target value k, find the maximum length of a subarray that sums to k. If t ...

  3. [LeetCode] Word Search 词语搜索

    Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from l ...

  4. Android,ios,WP三大手机系统对比

    从前,我以为.一个手机系统只是一个系统的UI风格,没什么不同的.然而,在我混合使用这三个手机系统之后,才明白,一个手机系统远不只一个UI那么简单,而真的是可以称之为一个“生态”. 首先祭出三台经典设备 ...

  5. jquery-三级联动

    html <!DOCTYPE html> <html> <head> <meta charset=gbk /> <title>selectL ...

  6. 个人作业-Week1

    问题1:程序员的优劣是否在软件开发中已经不重要了??用户实际关心的 外形,使用的乐趣和效率,自我形象,个人满足感,回忆,这么多条中,仅有效率与代码有关,而实际上用户比起效率却更在意其他这些“幺蛾子”. ...

  7. oschina代码仓库远程push,pull免密实操总结

    刚做项目,用到开源中国(oschina)的git仓库,一个多月一直在痛苦的反复输密码的过程中度过.中间配置过几次免密登录,但总是时而登的上去,时而不行,大多数情况不行.近几日项目做完了,正好有空把这个 ...

  8. CodeForces 698C LRU

    吐槽一句:这数据造得真强-. 题意:有一个大小为k的缓存区,每次从n种物品中按照一定的概率选取一种物品尝试放进去.同一个物品每一次选取的概率都是相同的.如果这种物品已经放进去过就不再放进去.如果缓存区 ...

  9. Codeforces Round #384 (Div. 2) B. Chloe and the sequence(规律题)

    传送门 Description Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems ...

  10. foreach

    一 foreach的语法介绍    PHP 4以上的版本包括了 foreach 结构,这只是一种遍历数组简便方法.foreach 仅能用于数组,当试图将其用于其它数据类型或者一个未初始化的变量时会产生 ...