很不好想的一道题,参考: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. [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字

    Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...

  2. DataSet与DataTable与DataRow的关系

    1. 添加数据: DataRow dr=MyDataSet.Tables["User"].NewRow(); dr["UserName"] = "张三 ...

  3. c#线程带参数

    c#线程带参数 ThreadStart threadStart = delegate { LoadPicture(ds.Tables[0]); }; Thread thread = new Threa ...

  4. Not Hello World

    通常对于一门语言的学习,一般都是以"Hello,World!"开始的.但对于汇编语言的学习,输出这句话并不容易,首先得了解寄存器等硬件知识. 汇编语言要得以运行,首先要讲源文件编译 ...

  5. framebuffer line_length 參數

    以下是在 trace 關機充電動畫所遇到一個疑惑, 關於 framebuffer device 的屬性 line_length 大小值, 一個 display panel,1920 × 1080, 每 ...

  6. Ceph RGW服务 使用s3 java sdk 分片文件上传API 报‘SignatureDoesNotMatch’ 异常的定位及规避方案

    import java.io.File;   import com.amazonaws.AmazonClientException; import com.amazonaws.auth.profile ...

  7. Django session cookie 上传文件、详解

    session 在这里先说session 配置URL from django.conf.urls import patterns, include, url from django.contrib i ...

  8. ABP文档 :Overall - Module System

    模块介绍 ABP提供了构建模块并将这些模块组合起来创建应用的基础设施.一个模块可以依赖另一个模块.一般来说,一个程序集可以认为是一个模块.如果应用中有多个程序集,建议为每个程序集创建一个模块定义.模块 ...

  9. Jmeter学习笔记ONE

    最近想学一些关于性能测试方面的知识,其实之前已经初步了解了Jmeter工具,它是一个轻量级的性能测试工具,开源并且免费,相比于Loadrunner来说用起来更简便. JMeter 可以用于对服务器.网 ...

  10. phpcms二次开发中无法获取SESSION的值

    今天在在phpcms开发留言板用到验证码,提交数据,后台无法$_SESSION['code']无法获取验证码值,也无法打印var_dump($_SESSION)值,我们只需要在文件头部添加如下代码: ...