【数据结构】CODE[VS] 2491 && bzoj 3039玉蟾宫 (单调
发布时间:2020-12-15 05:56:19 所属栏目:安全 来源:网络整理
导读:点击观看虹猫蓝兔七侠传 点击观看虹猫蓝兔七侠传(bzoj高端权限专版) 题意是让你求最大子矩阵和 就是最大子段和的二维扩展 做的时候,还是需要一些技巧的 这道题直接暴力搜肯定会TLE(大师难度 ,出题人不可能出简单的暴搜) 我们可以将原图的R,F矩阵转化为
点击观看<虹猫蓝兔七侠传>
神犇们都说是大水题。。。。。。。。。。 代码如下: //gtnd zcw
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <stack>
const int maxn = 2000;
using namespace std;
int n,m;
int map[maxn][maxn];
int h[maxn][maxn];
char c[1];
stack<int >s;
inline void rd(int &x)
{
scanf("%d",&x);
}
inline void add()
{
for(int i = 1;i <= n;i++)
for(int j = 1;j <= m;j++)
{
if(map[i][j] == 1) h[i][j] = h[i-1][j] + 1;
else h[i][j] = 0;
}
}
inline void work()
{
for(int i = 1;i <= n;i++)
for(int j = 1;j <= m;j++)
{
scanf("%s",c);
if(c[0] == 'R') map[i][j] = 0;
else map[i][j] = 1;
}
add();
int ans = 0;
//单调栈维护的是当前第i行上向上1数目最大的那一列的序号
for(int i = 1;i <= n;i++)
{
for(int j = 1; j <= m;j++)
{
ans = max(ans,h[i][j]);
int v = j;
while(!s.empty() && h[i][j] < h[i][s.top()])
{
v = s.top();
s.pop();
ans = max(ans,(j-v) * h[i][v]);
h[i][v] = h[i][j];
}
s.push(v);
}
while(!s.empty())
{
int u = s.top();
s.pop();
ans = max(ans,(m-u+1) * h[i][u]);
}
}
printf("%dn",ans*3);
return ;
}
int main()
{
rd(n);rd(m);
work();
return 0;
}
THE END By Peacefuldoge http://blog.csdn.net/loi_peacefuldog/ (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |