hdu2870 Largest Submatrix 单调栈
描述
就不需要描述了...
题解
被lyd的书的标签给骗了(居然写了单调队列优化dp??) 看了半天没看出来哪里是单调队列dp,表示强烈谴责QAQ
w x y z 可以各自 变成a ,b c 中的几种, 那么只需要考虑矩阵由 a, b 或 c 构成就可以了。
对于每一种情况都枚举一次, 比如现在考虑由 a 构成的矩阵, 只需要将能 w y z a 的位置记为 1, 其他位置记为 0 ,然后找面积最大的 由 1 组成的矩阵即可。
那么这题就是道 单调栈裸题了 ( 不会的同学可以去这边学
代码
我的单调栈好像有点丑。。。
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<stack>
#define rd read()
#define rep(i,a,b) for( int i = (a); i <= (b); ++i )
#define per(i,a,b) for( int i = (a); i >= (b); --i )
using namespace std; const int N = 1e3 + ; char s[N][N]; int n, m, mp[N][N], ans, h[N], pre[N], nxt[N]; stack<int> st; void cal() {
memset(h, , sizeof(h));
rep( i, , n ) {
rep( j, , m )
if( mp[i][j] ) h[j]++;
else h[j] = ;
while( st.size() ) st.pop();
rep( j, , m ) {
int pr = ;
while( !st.empty() ) {
pr = st.top();
if( h[pr] >= h[j] ) st.pop();
else break;
}
st.push(j);
pre[j] = pr;
} while( st.size() ) st.pop();
per( j, m, ) {
int nt = m + ;
while( !st.empty() ) {
nt = st.top();
if( h[nt] >= h[j] ) st.pop();
else break;
}
st.push(j);
nxt[j] = nt;
}
rep( j, , m ) {
int len = nxt[j] - pre[j] - ;
ans = max( ans, len * h[j] );
}
}
} int main()
{
while( scanf("%d%d",&n,&m) == ) {
ans = ;
rep( i, , n ) scanf("%s",s[i] + );
rep( i, , n ) rep( j, , m ) {
if( s[i][j] == 'w' || s[i][j] == 'y' || s[i][j] == 'z' || s[i][j] == 'a' ) mp[i][j] = ;
else mp[i][j] = ;
}
cal();
rep( i, , n ) rep( j, , m ) {
if( s[i][j] == 'w' || s[i][j] == 'x' || s[i][j] == 'z' || s[i][j] == 'b' ) mp[i][j] = ;
else mp[i][j] = ;
}
cal();
rep( i, , n ) rep( j, , m ) {
if( s[i][j] == 'x' || s[i][j] == 'y' || s[i][j] == 'z' || s[i][j] == 'c' ) mp[i][j] = ;
else mp[i][j] = ;
}
cal();
printf("%d\n", ans);
}
return ;
}
hdu2870 Largest Submatrix 单调栈的更多相关文章
- HDU 2870 Largest Submatrix (单调栈)
http://acm.hdu.edu.cn/showproblem.php? pid=2870 Largest Submatrix Time Limit: 2000/1000 MS (Java/Oth ...
- HDU2870 Largest Submatrix
Largest Submatrix Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- poj 2559 Largest Rectangle(单调栈)
Largest Rectangle in a Histogram Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26549 ...
- POJ-3494 Largest Submatrix of All 1’s (单调栈)
Largest Submatrix of All 1’s Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 8551 Ac ...
- Largest Submatrix of All 1’s(思维+单调栈)
Given a m-by-n (0,1)-matrix, of all its submatrices of all 1's which is the largest? By largest we m ...
- POJ 3494 Largest Submatrix of All 1’s 单调队列||单调栈
POJ 3494 Largest Submatrix of All 1’s Description Given a m-by-n (0,1)-matrix, of all its submatrice ...
- [POJ2559&POJ3494] Largest Rectangle in a Histogram&Largest Submatrix of All 1’s 「单调栈」
Largest Rectangle in a Histogram http://poj.org/problem?id=2559 题意:给出若干宽度相同的矩形的高度(条形统计图),求最大子矩形面积 解题 ...
- POJ - 3494 Largest Submatrix of All 1’s 单调栈求最大子矩阵
Largest Submatrix of All 1’s Given a m-by-n (0,1)-matrix, of all its submatrices of all 1’s which is ...
- SPOJ MINSUB - Largest Submatrix(二分+单调栈)
http://www.spoj.com/problems/MINSUB/en/ 题意:给出一个n*m的矩阵M,和一个面积k,要使得M的子矩阵M'的最小元素最大并且面积大于等于k,问子矩阵M'的最小元素 ...
随机推荐
- php yii 命令
php yii 敲回车 This is Yii version 2.0.11. The following commands are available: - asset Allows you to ...
- 重新装kafka
Linux搭建kafka 一.安装Java 1.查看linux 的系统版本 root@aliyun:~# uname --m x86_64 2.安装java mkdir -p /usr/local ...
- 04_web基础(二)之web构建
03.04.05.06web项目创建 07.第一个Servlet程序 1.拷贝tomcat 中的 servlet-api.jar 在lib包下面 2.新建一个HelloWordServlet类并实现 ...
- python 任务计划
sched 模块 引用time类实现任务定时执行 import time import sched def worker(msg): print msg s = sched.scheduler ...
- JMeter学习(三)元件的作用域与执行顺序(转载)
转载自 http://www.cnblogs.com/yangxia-test 1.元件的作用域 JMeter中共有8类可被执行的元件(测试计划与线程组不属于元件),这些元件中,取样器是典型的不与其它 ...
- 八、AbstractFactory 抽象工厂模式
设计原理: 代码清单: 抽象 Factory : public abstract class Factory { public static Factory getFactory(String cla ...
- js dongtai xianshi textarea zishu
<form name="FORM" id="FORM" method="post" action="?action=$atc ...
- c++三种进制格式
来源:c++ primer plus 常用的进制有二进制,八进制,十进制,十六进制,在c++的头文件iostream里除了提供了endl控制符之外,还提供了控制进制的控制符,(不含二进制),分别是八进 ...
- Codeforces Beta Round #35 (Div. 2)
Codeforces Beta Round #35 (Div. 2) http://codeforces.com/contest/35 A 这场的输入输出是到文件中的,不是标准的输入输出...没注意看 ...
- Java之成员访问控制
Java中数据成员.方法成员有四种访问控制.