BZOJ3039 最大01子矩阵 单调栈

//#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<iomanip>
#include<stack>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mem(a) memset(a,0,sizeof a)
#define FOR(a) for(int i=1;i<=a;i++)

const int maxn=1e3+7;
int mp[maxn][maxn];
int up[maxn][maxn];
int n,m;

void init(){
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			up[i][j]=(up[i-1][j]+1)*(mp[i][j]==1);
}

struct NODE{
	int h,w;
};
stack<NODE>S;

int work(){
	int ret=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			int tmp=0;
			while(!S.empty() && S.top().h>up[i][j]){
				tmp+=S.top().w;
				ret=max(ret,S.top().h*tmp);
				S.pop();
			}
			S.push((NODE){up[i][j],tmp+1});
		}
		int tmp=0;
		while(!S.empty()){
			tmp+=S.top().w;
			ret=max(ret,S.top().h*tmp);
			S.pop();
		}
	}
	return ret;
}

char buf[12];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			scanf("%s",buf);
			if(buf[0]=='F')mp[i][j]=1;else mp[i][j]=0;
		}
	}
	init();
	printf("%d\n",work()*3);
}

转载于:https://www.cnblogs.com/Drenight/p/8611228.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值