POJ3493 Largest Submatrix of All 1’s(单调栈)
题目给一个01矩阵,求最大的1子矩阵。
先用dp预处理出每一行的每一列的1能向上按连续的1延伸多少,然后枚举每一行作为子矩阵的底,那样对于每一行的答案就是POJ2559这个经典问题了。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXN 2222
int stack[MAXN],top,l[MAXN],r[MAXN];
int calc(int *a,int n){
a[++n]=-; top=;
for(int i=; i<=n; ++i){
l[i]=r[i]=i;
while(top && a[stack[top]]>a[i]){
r[stack[top]]=i-;
l[i]=l[stack[top]];
--top;
}
if(top && a[stack[top]]==a[i]) l[i]=l[stack[top]];
stack[++top]=i;
}
int res=;
for(int i=; i<n; ++i){
res=max(res,a[i]*(r[i]-l[i]+));
}
return res;
}
int d[MAXN][MAXN];
int main(){
int n,m;
while(~scanf("%d%d",&n,&m)){
for(int i=; i<=n; ++i){
for(int j=; j<=m; ++j) scanf("%d",&d[i][j]);
}
for(int i=; i<=n; ++i){
for(int j=; j<=m; ++j){
if(d[i][j]) d[i][j]=d[i-][j]+;
}
}
int res=;
for(int i=; i<=n; ++i){
res=max(res,calc(&d[i][],m));
}
printf("%d\n",res);
}
return ;
}
POJ3493 Largest Submatrix of All 1’s(单调栈)的更多相关文章
- POJ - 3494 Largest Submatrix of All 1’s 单调栈求最大子矩阵
Largest Submatrix of All 1’s Given a m-by-n (0,1)-matrix, of all its submatrices of all 1’s which is ...
- POJ 3494 Largest Submatrix of All 1’s 单调队列||单调栈
POJ 3494 Largest Submatrix of All 1’s Description Given a m-by-n (0,1)-matrix, of all its submatrice ...
- POJ3494Largest Submatrix of All 1’s[单调栈]
Largest Submatrix of All 1’s Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 5883 Ac ...
- poj 2559 Largest Rectangle in a Histogram (单调栈)
http://poj.org/problem?id=2559 Largest Rectangle in a Histogram Time Limit: 1000MS Memory Limit: 6 ...
- poj2559 Largest Rectangle in a Histogram(单调栈)
Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base l ...
- 题解报告:poj 2559 Largest Rectangle in a Histogram(单调栈)
Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base l ...
- HDU-1506 Largest Rectangle in a Histogram【单调栈】
Description A histogram is a polygon composed of a sequence of rectangles aligned at a common base l ...
- Largest Rectangle in a Histogram【单调栈模板】
Largest Rectangle in a Histogram 题目链接(点击)来源poj 2559 A histogram is a polygon composed of a sequence ...
- hdu_1506:Largest Rectangle in a Histogram 【单调栈】
题目链接 对栈的一种灵活运用吧算是,希望我的注释写的足够清晰.. #include<bits/stdc++.h> using namespace std; typedef long lon ...
- ☆ [POJ2559] Largest Rectangle in a Histogram 「单调栈」
类型:单调栈 传送门:>Here< 题意:给出若干宽度相同的矩形的高度(条形统计图),求最大子矩形面积 解题思路 单调栈的经典题 显然,最终的子矩形高度一定和某一个矩形相等(反证).因此一 ...
随机推荐
- sqlite 跨数据库查询
try { $dbh = new PDO($dbrootemp, null, null); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_ ...
- WinAPI: ExtCreateRegion - 区域变换
转载:http://www.cnblogs.com/del/archive/2008/06/03/1212534.html 相似函数: SetWorldTransform 本例效果图: 代码文件: u ...
- 暑假热身 B. 下载测速
最近,nono终于结束了每年一次的为期12个月的冬眠,醒来的第一件事就是——看电影!!nono发现最近一年出现了各种很好很强大的电影,例如这个.这个.还有这个. 于是nono直接把这些电影全部扔进了下 ...
- HDU3466背包01
Proud Merchants Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) ...
- 数学复习 ---- Mathematics Notes: A Programmer's Perspective ---- by Orzer ---- 我是沙茶
今年是好没长进的一年呢..只学了些基本的方法.. 本文记号0] x:p x类型为p1] f(x) 表示一个函数2] (n_1,n_2,...) 表示多元组,特别的,(n)表示一个一元组3] x 表示一 ...
- fsck检查和修复文件系统
重视:fsck不能乱用.先要把文件系统umount掉,然后检查.最好启动到单用户模式下fsck. 常见的5种损坏类型 1 未被引用的inode 2 难以置信的超大链接数 3 没有记录在磁盘块映射表中的 ...
- recv和send函数
转自 http://www.cnblogs.com/blankqdb/archive/2012/08/30/2663859.html 1. send解析 sockfd:指定发送端套接字描述符. bu ...
- @RequestBody, @ResponseBody 注解详解
简介: @RequestBody 作用: i) 该注解用于读取Request请求的body部分数据,使用系统默认配置的HttpMessageConverter进行解析,然后把相应的数据绑定到要返回的对 ...
- Java性能优化权威指南-读书笔记(五)-JVM性能调优-吞吐量
吞吐量是指,应用程序的TPS: 每秒多少次事务,QPS: 每秒多少次查询等性能指标. 吞吐量调优就是减少垃圾收集器消耗的CPU周期数,从而将更多的CPU周期用于执行应用程序. CMS吞吐调优 CMS包 ...
- Struts2中配置默认Action
1.当访问的Action不存在时,页面会显示错误信息,可以通过配置默认Action处理用户异常的操作:2.配置方法: 在struts.xml文件中的<package>下添加如下内容: ...