submatrix

given a 2-d matrix with 0 or 1 values

largest square of all 1‘s

dynamic programming, dp[i][j] = 1 + min{dp[i-1][j], dp[i][j-1], dp[i-1][j-1]} if m[i][j] == 1; otherwise a[i][j]=0;

largest submatrix of all 1‘s

https://leetcode.com/problems/maximal-rectangle/

dynamic programming. scan row-by-row and accumulate the "height" at each position; then for each accumulated row, run the "largest rectangle in histogram" algorithm.

query sum of submatrix
https://leetcode.com/problems/range-sum-query-2d-immutable/
similar to prefix-sum array, generate sum[i][j] = sum{mat[0..i][0..j]}, then it‘s straightforward to answer sum of all possible submatrixes.

largest sum of submatrix

column-wise (i, j) sum (i.e. sum columns[i..j]), then solve 1-D case in O(n), in total O(n^3)

时间: 2024-11-04 21:18:31

submatrix的相关文章

[LintCode] Submatrix Sum 子矩阵之和

Given an integer matrix, find a submatrix where the sum of numbers is zero. Your code should return the coordinate of the left-up and right-down number. Have you met this question in a real interview? Yes Example Given matrix [ [1 ,5 ,7], [3 ,7 ,-8],

Submatrix Sum

Given an integer matrix, find a submatrix where the sum of numbers is zero. Your code should return the coordinate of the left-up and right-down number. Subarray Sum的follow up.求二维矩阵上和为0的submatrix. 这题暴力解法枚举左上两坐标,右下两坐标,求中间和.复杂度为O(n^6).太高. 比较好的办法是枚举开始行和

Largest Submatrix(动态规划)

Largest Submatrix Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2018    Accepted Submission(s): 967 Problem Description Now here is a matrix with letter 'a','b','c','w','x','y','z' and you ca

POJ 3494 Largest Submatrix of All 1’s(单调栈)

题目: Largest Submatrix of All 1’s Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 5540   Accepted: 2085 Case Time Limit: 2000MS Description Given a m-by-n (0,1)-matrix, of all its submatrices of all 1’s which is the largest? By largest w

hdu 2870 Largest Submatrix

Largest Submatrix http://acm.hdu.edu.cn/showproblem.php?pid=2870 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Problem Description Now here is a matrix with letter 'a','b','c','w','x','y','z' and you can change '

POJ3494Largest Submatrix of All 1’s[单调栈]

Largest Submatrix of All 1’s Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 5883   Accepted: 2217 Case Time Limit: 2000MS Description Given a m-by-n (0,1)-matrix, of all its submatrices of all 1’s which is the largest? By largest we me

Max Sub-matrix

Max Sub-matrix 教练找的题目,目前样列过了 题意:找子矩阵的最大周长 思路:先离散每列,再枚举列(n*n),在当前枚举的两列之间求每行的和(n*n*n),但是开两个数组,一个包含两列上的元素  一个不包含,这样可以处理出前i行当前这两列上的元素和.  当前两列中每行元素和知道   两列上前i项和知道就可以找出最大值 1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #inc

HDU 2870 Largest Submatrix (单调栈)

http://acm.hdu.edu.cn/showproblem.php?pid=2870 Largest Submatrix Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1569    Accepted Submission(s): 748 Problem Description Now here is a matrix wit

CF 375B Maximum Submatrix 2[预处理 计数排序]

B. Maximum Submatrix 2 time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output You are given a matrix consisting of digits zero and one, its size is n × m. You are allowed to rearrange its rows. W

POJ 3494 Largest Submatrix of All 1&#39;s 栈的运用 好题

Language: Default Largest Submatrix of All 1’s Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 5185   Accepted: 1950 Case Time Limit: 2000MS Description Given a m-by-n (0,1)-matrix, of all its submatrices of all 1’s which is the largest