这三道题的关系是这样的,1505是1506的加强版,2870又是1505的加强版

如果按照上面由简到易的顺序来做的话,还是很简单的

这道题的思想就是 枚举+DP

因为某些字符可以变值,所以我们枚举a, b, c三个矩阵

分别求出对应的h数组以及最大子矩阵,再在里面求出一个最大值即可。

 //#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = ;
char map[maxn][maxn];
int h[][maxn], l[][maxn], r[][maxn]; int main(void)
{
#ifdef LOCAL
freopen("2870in.txt", "r", stdin);
#endif int row, col;
while(scanf("%d%d", &row, &col) == )
{
int i, j, k, t;
for(i = ; i < row; ++i)
scanf("%s", map[i]);
memset(h, , sizeof(h));
int ans = ;
for(i = ; i < row; ++i)
{
for(j = ; j < col; ++j)
{
switch(map[i][j])
{ //处理h数组
case 'a':
++h[][j], h[][j] = h[][j] = ;
break;
case 'b':
++h[][j], h[][j] = h[][j] = ;
break;
case 'c':
++h[][j], h[][j] = h[][j] = ;
break;
case 'w':
++h[][j], ++h[][j], h[][j] = ;
break;
case 'x':
++h[][j], ++h[][j], h[][j] = ;
break;
case 'y':
++h[][j], ++h[][j], h[][j] = ;
break;
case 'z':
++h[][j]; ++h[][j], ++h[][j];
}
}
l[][] = l[][] = l[][] = ;
r[][col-] = r[][col-] = r[][col-] = col-;
for(j = ; j < col; ++j)
for(k = ; k < ; ++k)
{
t = j;
while(t > && h[k][j] <= h[k][t-])
t = l[k][t-];
l[k][j] = t;
} for(j = col-; j >= ; --j)
for(k = ; k < ; ++k)
{
t = j;
while(t < col- && h[k][j] <= h[k][t+])
t = r[k][t+];
r[k][j] = t;
} for(j = ; j < col; ++j)
for(k = ; k < ; ++k)
ans = max(ans, (r[k][j]-l[k][j]+)*h[k][j]);
}
printf("%d\n", ans);
}
return ;
}

代码君

HDU 2870 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. hdu 2870 Largest Submatrix(平面直方图的最大面积 变形)

    Problem Description Now here is a matrix with letter 'a','b','c','w','x','y','z' and you can change ...

  3. Largest Submatrix(动态规划)

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

  4. POJ 3494 Largest Submatrix of All 1’s

    POJ 2796 Feel Good HDU 1506 Largest Rectangle in a Histogram 和这两题一样的方法. #include<cstdio> #incl ...

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

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

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

  7. codeforces 407D Largest Submatrix 3

    codeforces 407D Largest Submatrix 3 题意 找出最大子矩阵,须满足矩阵内的元素互不相等. 题解 官方做法 http://codeforces.com/blog/ent ...

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

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

随机推荐

  1. Assetbundle的杂七杂八

    使用Assetbundle时可能遇到的坑 一 24 十一郎未分类 No Comments 转自 http://www.unitymanual.com/blog-3571-132.html 1.Edit ...

  2. 原 JS监听回车事件

    原 JS监听回车事件 发表于2年前(2014-06-04 10:16)   阅读(6101) | 评论(0) 11人收藏此文章, 我要收藏 赞0 1月16日厦门 OSC 源创会火热报名中,奖品多多哦  ...

  3. 设置VMWARE通过桥接方式使用主机无线网卡上网

    原文:http://www.cnblogs.com/liongis/p/3265458.html 环境:WIN7旗舰版,台式机,U盘无线上网卡. 虚拟软件:VMware9.0,虚拟系统:CentOS6 ...

  4. C# WinForm窗口最小化到系统托盘

    * C# WinForm窗口最小化到系统托盘http://hi.baidu.com/kfxtgtqyapouyze/item/8ccfdcd5a174a7312a35c7c3 主要功能:(1).程序启 ...

  5. lightoj 1397 - Sudoku Solver

    思路:每次找出可能情况最少的位置枚举可能情况!!! poj2676和这题一样不过poj数据比较水,很容易过. 代码如下: #include<iostream> #include<cs ...

  6. 机器学习之神经网络模型-上(Neural Networks: Representation)

    在这篇文章中,我们一起来讨论一种叫作"神经网络"(Neural Network)的机器学习算法,这也是我硕士阶段的研究方向.我们将首先讨论神经网络的表层结构,在之后再具体讨论神经网 ...

  7. UVA 11609 Teams 组合数学+快速幂

    In a galaxy far far away there is an ancient game played among the planets. The specialty of the gam ...

  8. MyEclipse — Maven+Spring+Struts+Hibernate 整合 [学习笔记-5]

    测试项目 目录结构

  9. jquery常见问题

    1.下面哪种说法是正确的? 您的回答:jQuery 是 JavaScript 库 2.jQuery 使用 CSS 选择器来选取元素? 您的回答:错误 正确答案:正确 3.jQuery 的简写是? 您的 ...

  10. hdu2023 求平均成绩 ~~很闲~~~

    #include<iostream> #include<stdio.h> #include<math.h> #include<string.h> #in ...