题意 给你矩阵 由F 和 R组成 问你其中F最大的子矩阵(全是F)*3为多少
做法 我们枚举每个点作为左下角的矩形 那么他的高度就是h[i][j] 一行一行的去做单调栈 我们就知道 维护单调递增栈 一旦你的这个高度小于前面的高度 我就要回去 用st_h[p]*(j-st_p[p) 就是答案 就能解决啦
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
const int MAX_N = 1025;
int h[MAX_N][MAX_N],n,m;
int p,st_h[MAX_N],st_p[MAX_N];
char ch[5];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
for(int i = 1;i<=n;++i)
{
for(int j = 1;j<=m;++j)
{
scanf("%s",ch);
if(ch[0]=='F') h[i][j] = h[i-1][j] + 1;
else h[i][j] = 0;
}
h[i][m+1] = 0;
}
int ans = 0;
for(int i = 1;i<=n;++i)
{
p = 0;
int mx = 0;
for(int j = 1;j<=m+1;j++)
{
int mnp = j;
while(p&&h[i][j]<=st_h[p])
{
mx = max(mx,(j-st_p[p])*st_h[p]);
mnp = min(mnp,st_p[p]);
p--;
}
p++;st_h[p] = h[i][j];st_p[p] = mnp;
}
ans = max(ans,mx);
}
printf("%d\n",ans*3);
}
return 0;
}