【POJ】3494
来源:互联网 发布:java线程池下载多任务 编辑:程序博客网 时间:2024/06/09 04:46
http://poj.org/problem?id=3494
n*m的矩阵,元素为0或1,找出一个最大的全是1构成的矩阵,求其面积。
a[i][j]表示:第i行,以第j列为底的矩阵的最大高度。
枚举每一列,相当于以每一列为底的条形图,求最大的矩形面积。
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <queue>#include <stack>#include <vector>#include <numeric>#include <algorithm>using namespace std;const int maxn=2005;int a[maxn][maxn];int L[maxn],R[maxn];struct Node{ int num,h;}t[maxn];int F(int n,int cnt){ stack <Node> s; t[0].h=t[0].num=0; for (int i=1;i<=n;i++){ t[i].h=a[i][cnt]; t[i].num=i; } t[n+1].h=0; t[n+1].num=n+1; s.push(t[0]); for (int i=1;i<=n;i++){ if (t[i].h>=s.top().h){ s.push(t[i]); } else{ while (s.top().h>t[i].h){ Node tmp=s.top(); s.pop(); R[tmp.num]=i; L[tmp.num]=s.top().num; } s.push(t[i]); } } int ans=-1; for (int i=1;i<=n;i++){ ans=max(ans,t[i].h*(R[i]-L[i]-1)); } return ans;}int main(){ int n,m; while (cin >> n >> m){ for (int i=1;i<=n;i++){ a[i][0]=0; for (int j=1;j<=m;j++){ scanf("%d",&a[i][j]); if (a[i][j-1]&&a[i][j]){ a[i][j]+=a[i][j-1]; } } } int ans=-1; for (int j=1;j<=m;j++){ ans=max(ans,F(n,j)); } cout << ans << endl; }}
阅读全文
0 0
- POJ 3494
- 【POJ】3494
- poj 3494
- POJ 2559 最大矩形面积 poj 3494
- Poj 3494 (dp)
- poj 3494 单调栈
- poj 3494 单调栈
- POJ 3494(可以过)
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- java面试题:输出字符串每个字母出现的次数
- SQL触发器
- maven-springmvc-mybatis-log4j-mysql整合配置-日志配置输出执行SQL
- Mysql中如何设置日期字段默认值为当前日期
- 牛顿冷却定律--画像&时间衰减系数
- 【POJ】3494
- X86 寄存器 结构图
- 登录态,票据和token是个什么玩意儿?
- springboot xml简单实例
- 软件测试概念及分类整理汇总
- Django 开发学习笔记(3)- 编写自定义的页面
- 测试系列-CMMI 知识扫盲篇
- 算法练习(3):Median of Two Sorted Arrays
- 多线程同步机制2-深入理解synchronized关键字