题意:让你求的是由同一字母组成的最大子矩阵,w可以变成a或者b,x可以变成b或者c,y可以变成a或者c,z可以变成a或者b或者c。

分析:这是hdu 1506、hdu 1505的加强版,具体的分析看我的博客:http://www.cnblogs.com/jiangjing/p/3221423.html

代码实现:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
char str[]={'a','b','c','w','x','y','z'};
char map[][];
int bian[][]={{,,},{,,},{,,},{,,},{,,},{,,},{,,}};
int shuliang[][][];
int l[],r[];
int n,m;
int solve(int i)
{
int j,k,t,max=-;
for(k=;k<;k++)
{
l[]=;r[m]=m;
for(j=;j<=m;j++)
{
t=j;
while(t>&&shuliang[i][j][k]<=shuliang[i][t-][k])
t=l[t-];
l[j]=t;
}
for(j=m-;j>=;j--)
{
t=j;
while(t<m&&shuliang[i][j][k]<=shuliang[i][t+][k])
t=r[t+];
r[j]=t;
}
for(j=;j<=m;j++)
if(max<(r[j]-l[j]+)*shuliang[i][j][k])
max=(r[j]-l[j]+)*shuliang[i][j][k];
}
return max;
}
int main()
{
int i,j,k,t,res,temp;
while(scanf("%d%d",&n,&m)!=EOF)
{
res=-;
getchar();
for(i=;i<=n;i++)
scanf("%s",map[i]+);
memset(shuliang,,sizeof(shuliang));
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
for(k=;k<;k++)
{
if(map[i][j]==str[k])
{
for(t=;t<;t++)
{
if(bian[k][t]==)
shuliang[i][j][t]=shuliang[i-][j][t]+;
else
shuliang[i][j][t]=;
}
break;
}
}
}
temp=solve(i);
if(temp>res)
res=temp;
}
printf("%d\n",res);
}
return ;
}

hdu 2870(dp求最大子矩阵)的更多相关文章

  1. hdu 1505(dp求最大子矩阵)

    题意:就是让你求出全由F组成的最大子矩阵. 分析:这是hdu 1506的加强版,只不过这道题变成了2维的,那我们就一行一行的来.具体的分析见1506的博客:http://www.cnblogs.com ...

  2. hdu 1506(dp求最大子矩阵)

    题意:容易理解... 分析:对于每个单位矩阵,我们先求出连续比它高的最左边的下标假设为l,然后求出比它高的最右边的下标假设为r,然后矩阵的面积就是(r-l+1)*1:我们从左到 右扫一遍,求出每个点的 ...

  3. hdu 1506 Largest Rectangle in a Histogram ((dp求最大子矩阵))

    # include <stdio.h> # include <algorithm> # include <iostream> # include <math. ...

  4. hdu1506(dp求最大子矩阵)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1506 分析: 对于每个单位矩阵,我们先求出连续比它高的最左边的下标假设为l,然后求出比它高的最右边的下 ...

  5. hdu2870(dp求最大子矩阵)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2870 分析:分别转换成'a','b','c'三种来求,其实就跟hdu1505一样了... #inclu ...

  6. hdu 4293 dp求最大权值不重合区间

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4293 #include<cstdio> #include<cstring> # ...

  7. hdu1505(dp求最大子矩阵)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1505 分析: 这题是HDU 1506 的加强版,定义一个二维数组,d[i][j]表示第i行j列元素在前 ...

  8. HDU 4514 - 湫湫系列故事——设计风景线 - [并查集判无向图环][树形DP求树的直径]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4514 Time Limit: 6000/3000 MS (Java/Others) Memory Li ...

  9. BZOJ 1057: [ZJOI2007]棋盘制作 悬线法求最大子矩阵+dp

    1057: [ZJOI2007]棋盘制作 Description 国际象棋是世界上最古老的博弈游戏之一,和中国的围棋.象棋以及日本的将棋同享盛名.据说国际象棋起源于易经的思想,棋盘是一个8*8大小的黑 ...

随机推荐

  1. HDU 1829 A Bug's Life(种类并查集)

    思路:见代码吧. #include <stdio.h> #include <string.h> #include <set> #include <vector ...

  2. POJ 1922

    #include<iostream>cheng da cai zi 11.21 //#include<stdio.h> #include<math.h> using ...

  3. java基础知识回顾之java Thread类学习(三)--java线程实现常见的两种方式实现好处:

    总结:实现Runnable接口比继承Thread类更有优势: 1.因为java只能单继承,实现Runnable接口可以避免单继承的局限性 2.继承Thread类,多个线程不能处理或者共享同一个资源,但 ...

  4. Test Markdown Editor

    Last night, I just saw a cute blogger's homepage. Then I want to write something. But anyway, I use ...

  5. Intellij 导入play framework 项目

    新建一个项目 play new helloworld IshallbeThatIshallbe:~ iamthat$ mkdir temp IshallbeThatIshallbe:~ iamthat ...

  6. Mysql 分页语句Limit用法

    转载自:http://qimo601.iteye.com/blog/1634748 1.Mysql的limit用法 在我们使用查询语句的时候,经常要返回前几条或者中间某几行数据,这个时候怎么办呢?不用 ...

  7. LR_问题_无法使用LR的Controller,提示缺少license

    问题描述 无法使用LR的Controller,提示缺少license 问题解决 使用开始->所有程序->HP LoadRunner->loadrunner,在打开界面的左上角选择co ...

  8. POJ3009——Curling 2.0(DFS)

    Curling 2.0 DescriptionOn Planet MM-21, after their Olympic games this year, curling is getting popu ...

  9. chrome调试、移动端调试

    chrome 32版本后,添加 DevTools for Mobile 插件就可远程手机调试 DevTools for Mobile插件安装https://support.google.com/chr ...

  10. 类handler

    /** The handler class is the interface for dynamically loadable storage engines. Do not add ifdefs a ...