LeetCode 85. Maximal Rectangle

Solution1:
一语惊醒梦中人啊,参考链接:https://www.youtube.com/watch?v=2Yk3Avrzauk
根据第84题完成!

class Solution {
public:int maximalRectangle(vector<vector<char>>& matrix) {if (!matrix.size() || !matrix[0].size())return 0;int m = matrix.size(), n = matrix[0].size(), max_area = INT_MIN;;vector<vector<int> > dp(m, vector<int>(n, 0));for (int i = 0; i < m; i++) {for (int j = 0; j < n; j++) {if (i == 0)dp[i][j] = matrix[i][j] - '0';else {if (matrix[i][j] - '0')dp[i][j] = dp[i-1][j] + matrix[i][j] - '0';elsedp[i][j] = matrix[i][j] - '0';}}int temp_sum = largestRectangleArea(dp[i]);max_area = max(max_area, temp_sum);}return max_area;}int largestRectangleArea(vector<int>& height) {int res = 0;for (int i = 0; i < height.size(); ++i) {if (i + 1 < height.size() && height[i] <= height[i + 1]) {//若把这个判断条件去掉,则是暴力算法复杂度是O(n^2),只有最后一个case无法ACcontinue;}int minH = height[i];for (int j = i; j >= 0; --j) {minH = min(minH, height[j]);int area = minH * (i - j + 1);res = max(res, area);}}return res;}
};

【DP】LeetCode 85. Maximal Rectangle相关推荐

  1. LeetCode 85. Maximal Rectangle --python,java解法

    题目地址: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing only 1 ...

  2. leetcode 85. Maximal Rectangle | 85. 最大矩形(单调栈)

    题目 https://leetcode.com/problems/maximal-rectangle/ 题解 本题与 leetcode 84. Largest Rectangle in Histogr ...

  3. 【DP】LeetCode 64. Minimum Path Sum

    LeetCode 64. Minimum Path Sum Solution1:标准的动态规划题目 class Solution { public:int minPathSum(vector<v ...

  4. 【DP】LeetCode 53. Maximum Subarray

    LeetCode 53. Maximum Subarray Solution1:我的答案 动态规划 class Solution { public:int maxSubArray(vector< ...

  5. 【DP】LeetCode 120. Triangle

    LeetCode 120. Triangle Solution1:我的答案 真费劲啊!!! 啊!!!!!! class Solution { public:int minimumTotal(vecto ...

  6. LeetCode:完全平方数【279】【DP】

    LeetCode:完全平方数[279][DP] 题目描述 给定正整数 n,找到若干个完全平方数(比如 1, 4, 9, 16, ...)使得它们的和等于 n.你需要让组成和的完全平方数的个数最少. 示 ...

  7. 【DP】【期望】$P1850$换教室

    [DP][期望]\(P1850\)换教室 链接 题目描述 有 \(2n\) 节课程安排在$ n$ 个时间段上.在第 \(i\)(\(1 \leq i \leq n\))个时间段上,两节内容相同的课程同 ...

  8. Bailian2760 数字三角形【DP】

    2760:数字三角形 描述 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (图1) 图1给出了一个数字三角形.从三角形的顶部到底部有很多条不同的路径.对于每条路径,把路径上面的数加起来可 ...

  9. NUC1131 Triangle【DP】

    Triangle 时间限制: 1000ms 内存限制: 65536KB 通过次数: 1总提交次数: 1 问题描述 图1表示一个数字三角形. 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 ...

最新文章

  1. Win10 + ubuntu16双系统安装以及cuda,cudnn安装
  2. mysql低权限用户getshell_GetShell的姿势总结
  3. 也谈架构:百万pv项目与虚拟化
  4. mysql版本选择最终建议
  5. linux系统udp通信程序,Linux UDP socket编程(UDP通讯模型) | C/C++程序员之家
  6. 办大额信用卡致胜一招
  7. kali linux解密栅栏密码,最详细bugku加密小白解法---持续更新!
  8. python同步oracle_Python cx_Oracle 7引入苏打文档存储
  9. Java Springboot应用部署
  10. 怎么用git将本地代码上传到远程服务器_git之如何把本地文件上传到远程仓库的指定位置...
  11. Project Euler Problem 25 1000-digit Fibonacci number
  12. Java笔记:final修饰符
  13. 计算机网络工程师试题及答案,计算机软考网络工程师自测试题及答案汇总
  14. VM14装deepin-15.6-amd64
  15. 移动吉比特H2-2光猫超级用户与密码
  16. 转载:16种鲜鱼的做法
  17. 408 知识点笔记——操作系统(绪论、进程管理)
  18. Linux-系统管理16-磁盘配额
  19. mysql-mysql介绍
  20. 樱花飘落,3D效果,抖音热门樱花飘落html

热门文章

  1. 弗拉门戈-吉普赛婚礼-保利剧院
  2. 数据结构上机实践第四周项目4 - 建设双链表算法库
  3. phpexcel 数字格式_将文本转换为phpexcel中的数字格式
  4. 最大公约数简便算法_最大公约数的求法
  5. linux怎么启动ibus框架,fedora13 gnu/linux下 重启启动ibus输入法框架
  6. Ubuntu18.04下解决Qt出现qt.qpa.plugin:Could not load the Qt platform plugin “xcb“问题
  7. java servlet 3.1,Servlet 3.1规范学习小记
  8. bool型数组python_Python bool()
  9. android mvp_Android MVP
  10. 什么是SQL Server DATEPART()方法?