单调栈题解
2025-08-04 16:30:34
发布于:上海
9阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
const int N=1005;
long long a[N][N],dp[N][N];
char grid[N][N];
int n,m;
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>grid[i][j];
if(grid[i][j]=='F')dp[i][j]=dp[i-1][j]+1;
else dp[i][j]=0;
}
}
int ans=-1e9;
stack<int>st;
for(int i=1;i<=n;i++){
for(int j=1;j<=m+1;j++){
while(!st.empty()&&dp[i][st.top()]>dp[i][j]){
int idx=st.top();
st.pop();
int width;
if(st.empty())width=j;
else width=j-st.top()-1;
int area=dp[i][idx]*width;
if(area>ans)ans=area;
}
st.push(j);
}
}
cout<<ans*3;
return 0;
}
这里空空如也
有帮助,赞一个