码迷,mamicode.com
首页 > 其他好文 > 详细

单调栈--poj3494

时间:2019-09-09 22:45:54      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:cstring   return   class   type   out   inf   思路   scan   vector   

poj3494
思路:一行一行看,所在位置上1的高度先预处理出来,就成了经典单调栈问题

#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>

using namespace std;
typedef long long LL;
typedef pair<double, double> PDD;
typedef pair<LL, LL> PLL;

const LL N = 2e3+50;
const LL MOD = 1e9+7;
const LL INF = 0x3f3f3f3f;

#define lson l, m, rt>>1
#define rson m+1, r, rt>>1|1

int mp[N][N], dp[N][N];
int main()
{
    int n, m;
    while(scanf("%d%d", &n, &m) != EOF)
    {
        int ans = 0;
        memset(dp, 0, sizeof(dp));
        for(int i = 1;i <= n;++i)
        {
            for(int j = 1;j <= m;++j)
            {
                scanf("%d", &mp[i][j]);
                if(mp[i][j] == 1)
                    dp[i][j] = dp[i-1][j]+1;
            }
            dp[i][0] = dp[i][m+1] = -1;
        }
        for(int i = 1;i <= n;++i)
        {
            stack<int> s;
            int r[N];//以该点为最低的右闭边界
            s.push(m+1);
            for(int j = m;j;--j)
            {
                while(dp[i][s.top()] >= dp[i][j]) s.pop();
                r[j] = s.top();
                s.push(j);
            }
            while(!s.empty()) s.pop();
            s.push(0);
            for(int j = 1;j <= m;++j)
            {
                while(dp[i][s.top()] >= dp[i][j]) s.pop();
                ans = max(ans, dp[i][j]*(r[j]-s.top()-1));
                s.push(j);
            }
        }
        cout << ans << endl;
    }
    return 0;
}

单调栈--poj3494

标签:cstring   return   class   type   out   inf   思路   scan   vector   

原文地址:https://www.cnblogs.com/shuizhidao/p/11494558.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!