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'的最小元素 ...
随机推荐
- Winform 学生管理系统增删改查
数据库: create database adonet go use adonet go create table xue ( code ), name ), sex bit, birth datet ...
- k8s 创建deployment流程
pod 创建流程https://blog.csdn.net/yan234280533/article/details/72567261 api server -> etcd -> cont ...
- canvas画布内部重复画圆
<!DOCTYPE html><html><head> <title>canvas example</title> <meta cha ...
- matlab 画二维图与三维图
二维图 ezplot('sin(x)');%默认范围 ezplot('sin(x)',[-4 4]);%自己设定范围 三维图 ezmesh('x*x+y*y');%默认范围
- kangle web配置phpmyadmin
1. kangle安装参考:https://www.kangleweb.com/thread-6001-1-1.html 2. 安装mysql-5.7.22:http://www.cnblogs.co ...
- js保留小数点后面几位的方法
原文地址: http://www.jb51.net/article/45884.htm 四舍五入以下处理结果会四舍五入: ? 1 2 var num =2.446242342; num = num.t ...
- set集合,深浅拷⻉以及部分知识点补充
set集合,深浅拷⻉以及部分知识点补充内容:1. 基础数据类型补充2. set集合3. 深浅拷⻉主要内容: ⼀. 基础数据类型补充⾸先关于int和str在之前的学习中已经讲了80%以上了. 所以剩下的 ...
- 第十一章 串 (c2)KMP算法:查询表
- window中磁盘空间不足但是找不到使用空间的文件
今天看到 电脑的 d盘 空间爆红,空间满了,去找了找没有找到具体是哪个文件占用的空间.一个一个文件的查看属性,都没有找到.文件都不大,几百个g的空间就没了.莫名其妙!!! 自己开启了备份还原,存储的 ...
- 154. Find Minimum in Rotated Sorted Array II (Array; Divide-and-Conquer)
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand. (i.e. ...