bzoj 4506: [Usaco2016 Jan]Fort Moo

4506: [Usaco2016 Jan]Fort Moo

Description

Bessie is building a fort with her friend Elsie. Like any good fort, this one needs to start with a sturdy frame. Bessie wants to build a frame in the shape of a one-meter-wide rectangular outline, atop which she will build the fort.
Bessie has already chosen a site on which to build the fort -- a piece of land measuring NN meters by MM meters (1< = N,M< = 2001< = N,M< = 200). Unfortunately, the site has some swampy areas that cannot be used to support the frame. Please help Bessie determine the largest area she can cover with her fort (the area of the rectangle supported by the frame), such that the frame avoids sitting on any of the swampy areas.

Input

Line 1 contains integers N and M.
The next N lines each contain M characters, forming a grid describing the site. A character of '.' represents normal grass, while 'X' represents a swampy spot.

Output

A single integer representing the maximum area that Bessie can cover with her fort.

Sample Input

5 6
......
..X..X
X..X..
......
..X...

Sample Output

16
In the example, the placement of the optimal frame is indicated by 'f's below:
.ffff.
.fX.fX
Xf.Xf.
.ffff.
..X...
题解:
题目大意是找到一个最大的矩形使得矩形的外框均在不在沼泽上。
o(n4)的暴力我就不说了,也许会卡过。
讲一讲n3吧,我们只需枚举矩形的上下边界,然后用n的时间扫一遍。
#include<stdio.h>
#include<iostream>
using namespace std;
const int N=205;
char a[N][N];
int n,m,i,j,k,x,y,ans,b[N][N];
int main()
{
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)
        scanf("%s",a[i]+1);
    for(j=1;j<=m;j++)
     for(i=1;i<=n;i++)
     if(a[i][j]=='X') b[i][j]=b[i-1][j]+1;else b[i][j]=b[i-1][j];
    for(i=1;i<=n;i++)
     for(j=i;j<=n;j++)
    {
        x=0;y=0;
        for(k=1;k<=m;k++)
            if(b[j][k]-b[i-1][k]==0)
        {
            x=max(x,k);
            y=x;
            while(x<m&&a[i][x+1]=='.'&&a[j][x+1]=='.')
            {
                x++;
                if(b[j][x]-b[i-1][x]==0) y=x;
            }
            ans=max(ans,(j-i+1)*(y-k+1));
        }
    }
    cout<<ans;
    return 0;
}

 

转载于:https://www.cnblogs.com/lwq12138/p/5637819.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值