HDU 1505(City Game)动态规划-最大矩阵

这题就是1506的翻版,觉得应该把他们两个的题目序号换一下。

这个要预处理各个矩阵的高度,我是以竖的作为基准面,这样如果有j列,那就枚举j次最大,比较得出个最大的。

还有这题的输入并没有按照题目要求的那样 the next M lines contain N symbols that mark the reserved or free grid units,separated by a blank space

好多人栽在这里了,我也是看discuss才知道的。

代码:

#include<stdio.h>
#include<string.h>

int l[1005][1005],r[1005][1005],h[1005][1005];

int main()
{
    int T;
    int i,j,k,n,m,t,max;
    char ch,str[2];
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d",&n,&m);
        ch=getchar();
        memset(h,0,sizeof(h));
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                scanf("%s",str);
                if(str[0]=='F') h[i][j]=1;
                l[i][j]=i;
                r[i][j]=i;
            }
            ch=getchar();
        }
        //printf("\n");
        
        /*for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
                printf("%d ",h[i][j]);
            printf("\n");
        }*/
        
        /*for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
            {
                printf("%c ",map[i][j]);
            }
            printf("\n");
        }*/
        
        
        for(i=1;i<=n;i++)
        {
            for(j=m-1;j>=1;j--)
            {
                if(h[i][j+1]!=0 && h[i][j]!=0) h[i][j]=h[i][j+1]+1;
            }
        }
        for(j=1;j<=m;j++)
        {
            for(i=2;i<=n;i++)
            {
                if(h[i][j]==0) continue;
                t=i;
                while(h[i][j]<=h[t-1][j] && i>0)
                    t=l[t-1][j];
                l[i][j]=t;
            }
        }
        for(j=1;j<=m;j++)
        {
            for(i=n-1;i>=1;i--)
            {
                if(h[i][j]==0) continue;
                t=i;
                while(h[i][j]<=h[t+1][j] && t<=n-1)
                    t=r[t+1][j];
                r[i][j]=t;
            }
        }
        
        /*for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++)
                printf("%d ",h[i][j]);
            printf("\n");
        }*/
        
        max=-999999;
        for(j=1;j<=m;j++)
        {
            for(i=1;i<=n;i++)
            {
                t=(r[i][j]-l[i][j]+1)*h[i][j];
                if(max<t) max=t;
            }
        }
        printf("%d\n",max*3);
        //printf("100\n");
    }
    return 0;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值