POJ 3494 Largest Submatrix of All 1’s
HDU 1506 Largest Rectangle in a Histogram
和这两题一样的方法。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int maxn=+;
int a[maxn];
int L[maxn],R[maxn];
int m,n;
int tmp[maxn][maxn],b[maxn][maxn]; void f()
{
for(int i=; i<=n; i++) L[i]=i;
for(int i=; i<=n; i++)
{
if(a[i]>a[i-]) continue;
int pre=L[i-];
while()
{
L[i]=pre;
if(pre==||a[pre-]<a[i]) break;
pre=L[pre-];
}
} for(int i=n; i>=; i--) R[i]=i;
for(int i=n-; i>=; i--)
{
if(a[i]>a[i+]) continue;
int pre=R[i+];
while()
{
R[i]=pre;
if(pre==n||a[pre+]<a[i]) break;
pre=R[pre+];
}
} } int main()
{
while(~scanf("%d%d",&n,&m))
{
memset(b,,sizeof b);
for(int i=; i<=n; i++)
for(int j=; j<=m; j++) scanf("%d",&tmp[i][j]); for(int i=; i<=n; i++)
for(int j=; j<=m; j++)
{
if(tmp[i][j]==) continue;
b[i][j]=b[i][j-]+tmp[i][j];
} int ans=;
for(int j=;j<=m;j++)
{
for(int i=;i<=n;i++) a[i]=b[i][j];
f();
for(int i=;i<=n;i++) ans=max(ans,a[i]*(R[i]-L[i]+));
}
printf("%d\n",ans);
}
return ;
}
POJ 3494 Largest Submatrix of All 1’s的更多相关文章
- 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 ...
- 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(最大全1子矩阵)
题目链接:http://poj.org/problem?id=3494 题意:给出一个01的矩阵,找出一个面积最大的全1矩阵. 思路:用h[i][j]表示从位置(i,j)向上连续1的最大长度.之后枚举 ...
- POJ 3494 Largest Submatrix of All 1’s(最大子图形)
[题目链接] http://poj.org/problem?id=3494 [题目大意] 在01矩阵中求最大全1子矩形 [题解] 在处理每个点的时候,继承上一个点等高度下的左右最大扩展, 计算在该层的 ...
- [POJ2559&POJ3494] Largest Rectangle in a Histogram&Largest Submatrix of All 1’s 「单调栈」
Largest Rectangle in a Histogram http://poj.org/problem?id=2559 题意:给出若干宽度相同的矩形的高度(条形统计图),求最大子矩形面积 解题 ...
- POJ-3494 Largest Submatrix of All 1’s (单调栈)
Largest Submatrix of All 1’s Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 8551 Ac ...
- 第一周任务Largest Submatrix of All 1’s
Largest Submatrix of All 1’s Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 9512 Ac ...
- Largest Submatrix(动态规划)
Largest Submatrix Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- hdu 2870 Largest Submatrix(平面直方图的最大面积 变形)
Problem Description Now here is a matrix with letter 'a','b','c','w','x','y','z' and you can change ...
随机推荐
- mongodb 慢SQL查询
在 MySQL中,慢查询日志是经常作为我们优化数据库的依据,那在MongoDB中是否有类似的功能呢?答案是肯定的,那就是Mongo Database Profiler.不仅有,而且还有一些比MySQL ...
- nginx+php-fpm 的配置下,php的错误日志
发现php 运行错误时,浏览器的网页上并没有输出php的错误日志.那php的错误日志在哪里呢? 发现在 /var/log/nginx/error.log文件中. 怎么样才能在浏览器的网页中输出php的 ...
- 【jsp 分页】mysql limit方式进行分页
项目结构示意图: splitPage |-com.balfish.bean Goods.java |-com.balfish.dao GoodsDao.java |-com.bal ...
- keepalived: Compile & startup
first get keepalived source from git: git clone https://github.com/acassen/keepalived then unzip and ...
- Note over Chinese Encodings
I been confused years ago. Till recently I collected my thoughts together, and now I am clear about ...
- js 关键字 in
对于数组 ,迭代出来的是数组元 素,对于对象 ,迭代出来的是对象的属性: var x var mycars = new Array() mycars[0] = "Saab" myc ...
- Git学习 -- 自定义Git
忽略特殊文件 在工作区创建.gitignore文件,编写内容 # Windows: Thumbs.db ehthumbs.db Desktop.ini # Python: 忽略Python编译产生的. ...
- 使用libvirt做适配的kvm虚拟机window server 2008 磁盘性能的提升
实验室自己做了一个iaas的项目,当时是为了更方面的在kvm和xen下进行迁移,所以选择了libvirt作为适配层. 昨天简单的测试一了一下我们跟qingcloud的性能对比.我们的linux主机性能 ...
- 笔记整理--Linux编程
linux c编程open() read() write()函数的使用方法及实例 | 奶牛博客 - Google Chrome (2013/8/31 17:56:10) 今天把文件IO操作的一些东东整 ...
- 利用未文档化API:RtlAdjustPrivilege 提权实现自动关机
这里主要是利用NTDLL.dll中未文档化的API: RtlAdjustPrivilege 来实现提权.自动关机的功能. RtlAdjustPrivilege定义如下: NTSTATUS RtlAdj ...