Bzoj 4506: [Usaco2016 jan]fort Moo

Source: Internet
Author: User

4506: [Usaco2016 jan]fort MooDescriptionBessie 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'll build the fort.Bessie have 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 is used to support the frame. Bessie determine the largest area she can cover with her fort (the area of the rectangle supported by the Fram e), such the frame avoids sitting on any of the swampy areas.InputLine 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.OutputA Single integer representing the maximum area this Bessie can cover with her fort.Sample Input5 6
......
.. X.. X
X.. X..
......
.. X ...Sample Output16
In the example, the placement of the optimal frame are indicated by ' F ' s below:
. ffff.
. fx.fx
Xf.xf.
. ffff.
.. X ...The following:The main idea is to find a maximum rectangle so that the rectangle's bounding box is not on the swamp. O (N4) Violence I will not say, may be stuck. Speaking of N3, we just need to enumerate the upper and lower bounds of the rectangle, and then sweep through the time of N.
#include <stdio.h>#include<iostream>using namespacestd;Const intn=205;CharA[n][n];intN,m,i,j,k,x,y,ans,b[n][n];intMain () {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;Elseb[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;}

Bzoj 4506: [Usaco2016 jan]fort Moo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.