poj3494

给定一个01矩阵,求出面积最大的1矩阵。


一行一行来,就变成基本的求直方图的最大面积的情况了。

在poj上要用scanf和printf否则超时


#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <deque>
#include <cstring>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cstdlib>
#include <iomanip>
using namespace std;

#define rep(i, a, b) for( i = (a); i <= (b); i++)
#define reps(i, a, b) for( i = (a); i < (b); i++)
#define pb push_back
#define ps push
#define mp make_pair
#define CLR(x,t) memset(x,t,sizeof x)
#define LEN(X) strlen(X)
#define F first
#define S second
#define Debug(x) cout<<#x<<"="<<x<<endl;


const double euler_r = 0.57721566490153286060651209;
const double pi = 3.141592653589793238462643383279;
const double E = 2.7182818284590452353602874713526;
const int inf=~0U>>1;
const int MOD = int(1e9) + 7;
const double EPS=1e-6;

typedef long long LL;
int a[5050][5050], l[5050], r[5050], h[5050];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int n, m, i, j, k, ans, t;
    string s;
    cin >> n >> m;
    for(i = 1; i <= n; i++)
    {
        cin >> s;
        for(j = 1; j <= m; j++) a[i][j] = s[j-1] - '0';
    }
    ans = 0;
    rep(i, 1, m) h[i] = 0;

    rep(i, 1, n)
    {
        h[0] = h[m+1] = -1;
        for(k = 1; k <= m; k++)
        {
            if(a[i][k]) h[k]++;
            else h[k] = 0;
        }
        for(j = 1; j <= m; j++)
        {
            t = j;
            while(h[t-1] >= h[j]) t = l[t-1];
            l[j] = t;
        }
        for(j = m; j >= 1; j--)
        {
            t = j;
            while(h[t+1] >= h[j]) t = r[t+1];
            r[j] = t;
        }

        for(j = 1; j <= m; j++)
        {
            ans = max(ans, h[j] * (r[j] - l[j] + 1));
        }
    }
    cout << ans << endl;
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值