【POJ】3494 Largest Submatrix of All 1’s
2012-07-19 20:52
253 查看
#include<cstdio> #include<algorithm> #define MAXN 2010 using namespace std; int a[MAXN][MAXN]; struct node { int w,h; }st[MAXN]; int main() { node temp; int n,m,i,j,ans,top,wide; while(~scanf("%d%d",&n,&m)) { for(i=0;i<n;i++) { for(j=0;j<m;j++) scanf("%d",&a[i][j]); } for(i=1;i<n;i++) { for(j=0;j<m;j++) { if(a[i][j]) a[i][j]+=a[i-1][j]; } } for(ans=i=0;i<n;i++) { top=-1; for(j=0;j<m;j++) { for(wide=0;top>-1&&st[top].h>=a[i][j];top--) { wide+=st[top].w; ans=max(ans,wide*st[top].h); } temp.w=wide+1; temp.h=a[i][j]; st[++top]=temp; } for(wide=0;top>-1;top--) { wide+=st[top].w; ans=max(ans,st[top].h*wide); } } printf("%d\n",ans); } return 0; }
相关文章推荐
- poj 3494 Largest Submatrix of All 1’s(单调栈)
- POJ-3494 Largest Submatrix of All 1’s(单调栈)
- POJ 3494 Largest Submatrix of All 1’s 单调栈(数组版)
- POJ 3494 Largest Submatrix of All 1’s 笔记
- POJ 3494 Largest Submatrix of All 1’s(最大子图形)
- 2017省选拔(二)poj3494 Largest Submatrix of All 1’s (单调栈+预处理)
- poj 3494 Largest Submatrix of All 1’s
- POJ-3494-Largest Submatrix of All 1’s-还是单调栈
- POJ 3494 Largest Submatrix of All 1’s 单调栈应用 图解+代码详解
- POJ 3494 Largest Submatrix of All 1's 栈的运用 好题
- poj 3494 Largest Submatrix of All 1’s(单调栈)
- 【POJ】3494 - Largest Submatrix of All 1’s 栈
- (POJ 3494)Largest Submatrix of All 1’s (DP、单调栈)
- POJ - 3494 Largest Submatrix of All 1’s(单调栈)
- Largest Submatrix of All 1’s(POJ 3494) 单调栈
- poj 3494 Largest Submatrix of All 1’s
- poj3494 Largest Submatrix of All 1’s 单调栈+dp
- POJ 3494 Largest Submatrix of All 1’s
- POJ-3494-Largest Submatrix of All 1’s
- poj 3494 Largest Submatrix of All 1’s 单调栈/DP迭代法