杭电1505 City Game-DP问题

 


杭电1505 City Game

http://acm.hdu.edu.cn/showproblem.php?pid=1505
/*题目大意:
N*M矩阵,F为空,R不为空,求最大子矩阵的3*面积
解题思路:
求矩阵的高度h[i][j]=h[i-1][j]+1(op[i][j]='F')否则为h[i][j]=0.
接下来就与1506求子矩阵的面积类似了。对每行h[i]做处理,
h[i][j]为高度,求最大矩阵面积,循环N次求出MAX
代码如下:
*/
//n*m矩阵
#include<stdio.h>
#include<string.h>
char op[1005][1005];
int h[1005][1005];
int l[1005];
int r[1005];
int m, n;
void set()
{
int i,j;
for(j=1;j<=m;j++)
h[0][j]=0;
for(i=1;i<=m;i++)
for(j=1;j<=m;j++)
{
if(op[i][j]=='F')
h[i][j]=h[i-1][j]+1;
else
h[i][j]=0;
}
}
int getArea()
{
set();
int max=-1;
int i,j;
for(i=1;i<=n;i++)
{
memset(l,0,sizeof(l));
memset(r,0,sizeof(r));
for(j=1;j<=m;j++)
{
l[j]=j;
while(h[i][j]<=h[i][l[j]-1]&&l[j]>1)
l[j]=l[l[j]-1];
}
for(j=m;j>=1;j--)
{
r[j]=j;
while(h[i][j]<=h[i][r[j]+1]&&r[j]<m)
r[j]=r[r[j]+1];
}
for(j=1;j<=m;j++)
{
int x=h[i][j]*(r[j]-l[j]+1);
max=max>x?max:x;
}
}
return max;
}
int main()
{
int cas;
scanf("%d",&cas);
while(cas--)
{
scanf("%d%d",&n,&m);
char is[5];
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
scanf("%s",is);
op[i][j]=is[0];
}
int area=getArea();
printf("%d\n",3*area);
}
return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值