zoukankan      html  css  js  c++  java
  • 【POJ】3494 Largest Submatrix of All 1’s

     1 #include<cstdio>
     2 #include<algorithm>
     3 #define MAXN 2010
     4 using namespace std;
     5 int a[MAXN][MAXN];
     6 struct node
     7 {
     8     int w,h;
     9 }st[MAXN];
    10 int main()
    11 {
    12     node temp;
    13     int n,m,i,j,ans,top,wide;
    14     while(~scanf("%d%d",&n,&m))
    15     {
    16         for(i=0;i<n;i++)
    17         {
    18             for(j=0;j<m;j++)
    19                 scanf("%d",&a[i][j]);
    20         }
    21         for(i=1;i<n;i++)
    22         {
    23             for(j=0;j<m;j++)
    24             {
    25                 if(a[i][j])
    26                     a[i][j]+=a[i-1][j];
    27             }
    28         }
    29         for(ans=i=0;i<n;i++)
    30         {
    31             top=-1;
    32             for(j=0;j<m;j++)
    33             {
    34                 for(wide=0;top>-1&&st[top].h>=a[i][j];top--)
    35                 {
    36                     wide+=st[top].w;
    37                     ans=max(ans,wide*st[top].h);
    38                 }
    39                 temp.w=wide+1;
    40                 temp.h=a[i][j];
    41                 st[++top]=temp;
    42             }
    43             for(wide=0;top>-1;top--)
    44             {
    45                 wide+=st[top].w;
    46                 ans=max(ans,st[top].h*wide);
    47             }
    48         }
    49         printf("%d\n",ans);
    50     }
    51     return 0;
    52 }
  • 相关阅读:
    测试管理工具
    测试用例--zy
    测试计划和测试用例
    测试用例
    软件测试基础
    异步任务 ---- django-celery
    图片验证码接口
    测试作业
    数据库原理
    HTTPS原理
  • 原文地址:https://www.cnblogs.com/DrunBee/p/2599967.html
Copyright © 2011-2022 走看看