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'的最小元素 ...
随机推荐
- 判断用户 是用的电脑还是手机 判断 是安卓还是IOS
$(function(){ var Terminal = { // 辨别移动终端类型 platform: function () { var u = navigator.userAgent, app ...
- linux内核配置 kbuild
Linux 内核配置机制 http://blog.csdn.net/dianhuiren/article/details/6917132 linux kbuild文档 http://blog.chin ...
- 关于小程序 scroll-view 左右横向滑动没有效果(无法滑动)问题
https://www.cnblogs.com/miu-key/p/7606024.html
- 搭建php渗透测试环境
php服务器下载地址 http://vdisk.weibo.com/s/D9I4jIIfNddvh 在C盘下创建一个www文件夹 安装phpstudy 下一步安装 修改配置文件 将端口改成8080 保 ...
- Mysql 数据库 创建与删除(基础2)
创建数据库 语法: 注意:创建数据库时可以指定编码(如: create database mydb123 default charset utf8; ) pyvip@Vip:~$ mysql -uxl ...
- Android开发之getX,getRawX,getWidth,getTranslationX等的区别
转载请注明出处:http://blog.csdn.net/dmk877/article/details/51550031 好久没写博客了,最近工作确实挺忙的,刚刚结束了一个TV项目的开发,对 ...
- hibernate 中,出现了错误 "node to traverse cannot be null!" 如何改正
这个错误基本上是因为hql语句写错了而造成的, 返回找hql输出一下发现, hql语句中间少了几个空格, 写成了String hql = "from"+className+&quo ...
- Mac IntelliJ IDEA 2017(java开发集成环境)附注册码和破解教程 v2017.3.5破解版
原文:http://www.orsoon.com/Mac/155938.html 原文中含有软件下载地址 软件介绍 IntelliJ IDEA 2017 Mac激活版是Mac平台上的一款java开发集 ...
- MysqlMd5加密
MD5加密成功
- Fibonacci again and again
Fibonacci again and again http://acm.hdu.edu.cn/showproblem.php?pid=1848 Time Limit: 1000/1000 MS (J ...