P4147 玉蟾宫
题意:
给你一个n * m的矩阵,矩阵每个值有F或R,求最大的全为F的矩阵,输出面积 * 3
题解:
很明显,求最大01矩阵,悬线法或者单调栈
对于模板除了要记熟还要知道原理,不能光搬运,还要会调整
代码:
#include<bits/stdc++.h>
#define debug(a,b) printf("%s = %d\n",a,b);
typedef long long ll;
using namespace std;
//Fe~Jozky
const ll INF_ll=1e18;
const int INF_int=0x3f3f3f3f;
inline ll read(){ll s=0,w=1ll;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')w=-1ll;ch=getchar();}while(ch>='0'&&ch<='9') s=s*10ll+((ch-'0')*1ll),ch=getchar();//s=(s<<3)+(s<<1)+(ch^48);return s*w;
}
const int maxn=2000;
int a[maxn][maxn];
int up[maxn][maxn];
int Left[maxn][maxn];
int Right[maxn][maxn];
inline int R(){char ch=getchar();while(ch!='F'&&ch!='R'){ch=getchar();}if(ch=='F')return 1;return 0;
}
inline int max(int x,int y){return x>y?x:y;
}
inline int min(int x,int y){return x<y?x:y;
}
int main()
{int n,m;cin>>n>>m;char ch=getchar();for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){a[i][j]=R();}}for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){if(a[i][j])up[i][j]=1;else up[i][j]=0;Left[i][j]=Right[i][j]=j;}}for(int i=1;i<=n;i++){for(int j=2;j<=m;j++){if(a[i][j]==1&&a[i][j-1]==1)Left[i][j]=Left[i][j-1];}for(int j=m-1;j>=1;j--){if(a[i][j]==1&&a[i][j+1]==1)Right[i][j]=Right[i][j+1];}}int maxx=0;for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){if(a[i][j]&&a[i-1][j]&&i>1){up[i][j]=up[i-1][j]+1;Left[i][j]=max(Left[i][j],Left[i-1][j]);Right[i][j]=min(Right[i][j],Right[i-1][j]);}maxx=max(maxx,(Right[i][j]-Left[i][j]+1)*up[i][j]);}}cout<<maxx*3;return 0;
}