描述

就不需要描述了...

题目传送门

题解

被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 单调栈的更多相关文章

  1. HDU 2870 Largest Submatrix (单调栈)

    http://acm.hdu.edu.cn/showproblem.php? pid=2870 Largest Submatrix Time Limit: 2000/1000 MS (Java/Oth ...

  2. HDU2870 Largest Submatrix

    Largest Submatrix Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  3. poj 2559 Largest Rectangle(单调栈)

    Largest Rectangle in a Histogram Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 26549 ...

  4. POJ-3494 Largest Submatrix of All 1’s (单调栈)

    Largest Submatrix of All 1’s Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 8551   Ac ...

  5. 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 ...

  6. 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 ...

  7. [POJ2559&POJ3494] Largest Rectangle in a Histogram&Largest Submatrix of All 1’s 「单调栈」

    Largest Rectangle in a Histogram http://poj.org/problem?id=2559 题意:给出若干宽度相同的矩形的高度(条形统计图),求最大子矩形面积 解题 ...

  8. 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 ...

  9. SPOJ MINSUB - Largest Submatrix(二分+单调栈)

    http://www.spoj.com/problems/MINSUB/en/ 题意:给出一个n*m的矩阵M,和一个面积k,要使得M的子矩阵M'的最小元素最大并且面积大于等于k,问子矩阵M'的最小元素 ...

随机推荐

  1. export default 与 export

    export default 只能导出一个 可以用任意的变量来接收 export 可以暴露多个成员,需要用 import {} 接受成员 需要用名字接受 名字必须跟导出名字一致  //或者as作为别名 ...

  2. HTML5 data属性

    在HTML5中添加了data-*的方式来自定义属性,所谓data-*实际上上就是data-前缀加上自定义的属性名,命名可以用驼峰命名方式,但取值是必需全部使用小写,否则是undefinde 使用这样的 ...

  3. 微擎框架下拉分页(使用js模板引擎)

    1.需要分页的页面,引入一下文件 <script language="javascript" src="\addons\{$_GPC['m']}\template\ ...

  4. java spring bean的什么周期

    http://www.cnblogs.com/TIMHY/p/7794973.html

  5. css 鼠标选中内容背景色

    ::selection { background: rgba(32, 178, 170, .6); color: #ffffff; } ::-moz-selection { background: r ...

  6. keras初探

    1.对网络的理解: 2.怎样训练,输入已经数据,经过训练,输入测试数据,得到相似数据 3.RNNs  循环神经网络

  7. 05_ssm基础(四)之Spring与持久层的整合

    30.31.spring对jdbc的支持jdbcTemplate 使用Spring的JDBC准备:  1):拷贝jar:       mysql-connector-java-5.1.11.jar:M ...

  8. linux 根据服务名称批量杀死进程

    ps -ef |grep python |awk '{print $2}'|xargs kill -9

  9. CentOS7.x安装flash

    1.配置 yum 源 sudo rpm -ivh http://linuxdownload.adobe.com/adobe-release/adobe-release-x86_64-1.0-1.noa ...

  10. docker的理解

    作者:刘允鹏链接:https://www.zhihu.com/question/28300645/answer/67707287来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明 ...