zoukankan      html  css  js  c++  java
  • 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
    ",work()*3);
    }

  • 相关阅读:
    Stepping Number
    Replace String
    String Permutation
    Clock Angle
    Keypad Permutation
    Replace Words
    1、奉加微 PHY6202 Get started
    Python3 修改二进制文件
    Google Fast Pair
    python 校验 BLE resolvable private address
  • 原文地址:https://www.cnblogs.com/Drenight/p/8611228.html
Copyright © 2011-2022 走看看