Maximum Submatrix 2
来源:互联网 发布:手机虚拟按键软件 编辑:程序博客网 时间:2024/05/22 00:27
You are given a matrix consisting of digits zero and one, its size is n × m. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of ones and can be obtained in the given problem by the described operations?
Let's assume that the rows of matrix a are numbered from 1 ton from top to bottom and the columns are numbered from 1 tom from left to right. A matrix cell on the intersection of thei-th row and the j-th column can be represented as(i, j). Formally, a submatrix of matrixa is a group of four integers d, u, l, r (1 ≤ d ≤ u ≤ n; 1 ≤ l ≤ r ≤ m). We will assume that the submatrix contains cells(i, j) (d ≤ i ≤ u; l ≤ j ≤ r). The area of the submatrix is the number of cells it contains.
The first line contains two integers n andm (1 ≤ n, m ≤ 5000). Nextn lines contain m characters each — matrixa. Matrix a only contains characters: "0" and "1". Note that the elements of the matrix follow without any spaces in the lines.
Print a single integer — the area of the maximum obtained submatrix. If we cannot obtain a matrix of numbers one, print 0.
Input
1 11
Output
1
Input
2 21011
Output
2
Input
4 3100011000101
Output
2
题意
给你一个01矩阵,行与行之间可以交换位置
然后问你构成构成最大的只含1的矩形的面积是多少
题解:
我们分析一下,首先我们预处理一下
dp[i][j]表示第i列第j行往左边最远能延长多远
因为列是不会变的,所以我们对于每一列都排序,然后利用dp的思想往下找
到dp[i][j]==0的时候break,因为显然剩下的都是0了
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;char map[5500][5500];int h[5500][5500],n,m,ans=0;bool cmp(int a,int b){ return a>b;}int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) scanf("%s",map[i]+1); for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { if(map[i][j]=='1') h[j][i]=h[j-1][i]+1; } } for(int i=1;i<=m;i++) { sort(h[i]+1,h[i]+n+1,cmp); for(int j=1;j<=n;j++) { if(h[i][j]==0) break; ans=max(ans,h[i][j]*j); } } printf("%d\n",ans);}
- Maximum Submatrix 2
- B. Maximum Submatrix 2----dp
- Maximum Submatrix
- CodeForces 375B Maximum Submatrix 2
- CodeForces 375 B. Maximum Submatrix 2
- CodeForce 375B D - Maximum Submatrix 2
- dp cf B. Maximum Submatrix 2
- cf dp B. Maximum Submatrix 2
- Maximum Submatrix & Largest Rectangle
- SCU 2096 Maximum Submatrix
- Codeforces Round #221 (Div. 2)-D. Maximum Submatrix 2
- codeforces 375B B. Maximum Submatrix 2(dp)
- CF 376D. Maximum Submatrix 2 枚举+前缀和
- CodeForces 375B Maximum Submatrix 2(思维)
- Codeforces Round #221 (Div. 2) D. Maximum Submatrix 2 (思维题)
- CF:375B - Maximum Submatrix 2 不太像DP(sort的升序快速方法)
- Codeforces Round #221 (Div. 1) B. Maximum Submatrix 2 dp排序
- soj 3329 Maximum Submatrix II【转帖】
- Linux远程服务器之间下拷贝文件不输入密码
- POJ 1469 COURSES
- BZOJ 3538 == 洛谷 P3106 [USACO14OPEN]GPS的决斗Dueling GPS's
- 51 Nod 1678 lyk与gcd
- HDU 2063 过山车
- Maximum Submatrix 2
- 求LCA最近公共祖先的在线ST算法_C++
- 前端性能优化
- 2017年android面试总结
- 洛谷 P1174 打砖块
- Tomcat web服务器中Catalina命名的由来
- 洛谷 P1783 海滩防御
- 查找div标签下的a标签的内容
- 洛谷 P1362 兔子数