TYVJ1939 Jade Toad Hall

Source: Internet
Author: User

Background one day, kitten Rainbow and Freda came to the west Hunan Zhangjiajie Tianmen Mountain Jade Toad Hall, Jade Toad Hall Palace main Blue Rabbit hospitality to them, and give them a piece of land. The land is divided into n*m squares, each of which reads ' R ' or ' F ', and R represents the land that was given to rainbow,f to represent the land was given Freda.
Now Freda is here to sell Moe ... It is looking for a rectangular piece of land, requiring the land to be labeled ' F ' and the largest area.
But Rainbow and Freda Oi level are weak burst, can't find this piece of land, and blue Rabbit also want to see Freda sell Moe (she obviously won't program ...) So they decide that if you find a land area of s, they each give you s two silver. Input format the first line of two integer n,m, indicating that the rectangular land has n rows M column.
The next n lines, each with a space-separated character ' F ' or ' R ', describe the rectangular land. Output format output An integer that indicates how much money you can get, i.e. the value of the maximum ' F ' rectangular land area. Test Sample 1 input
5 6
R F F f f f
F F f f f f
R-R R F F F
F F f f f f
F F f f f f
Output
$
Note for 50% of data, 1<=n,m<=200
For 100% of data, the 1<=n,m<=1000 scan processes each column. For each column J, enumerate the length of F on the column H[j], and then sweep from left to right, looking for h[j] the height of F can extend to the left to how far, and then from right to left, looking for the right to extend the distance. After the left and right boundary and height are determined, the area is calculated and the optimal solution is updated. The minimum height is maintained in the process of left and right scanning with a monotonic stack.
1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5#include <cmath>6 using namespacestd;7 Const intmxn= -;8 intSt[mxn],top;9 intH[MXN];Ten intMP[MXN][MXN]; One intLE[MXN],RE[MXN]; A intans=0; - intn,m; - voidRead () {//Read in the     Chars; -      for(intI=1; i<=n;i++){ -          for(intj=1; j<=m;j++){ -s=GetChar (); +              while(s!='F'&& s!='R') s=GetChar (); -Mp[i][j]= (s=='F'); +         } A     } at     return; - } - intMain () { -scanf"%d%d",&n,&m); -     inti,j; - read (); in      for(i=1; i<=n;i++) {//Line -          for(j=1; j<=m;j++) {//column to             if(Mp[i][j]) h[j]++; +             Elseh[j]=0; -         } thetop=0; *st[0]=0; $          for(j=1; j<=m;j++){Panax Notoginseng              while(Top && h[st[top]]>=h[j]) top--;//monotonic Stack Maintenance boundary -Le[j]=st[top];//left Border theSt[++top]=j;//into the stack +         } Atop=0; thest[0]=m+1; +          for(j=m;j;j--){ -              while(Top && h[st[top]]>=h[j]) top--; $re[j]=st[top]-1; $st[++top]=J; -         } -          for(j=1; j<=m;j++){ the //printf ("test:i:%d j:%d l:%d r:%d h:%d \ n", I,j,le[j],re[j],h[j]); -Ans=max (ans, (re[j]-le[j]) *h[j]);Wuyi         } the     } -printf"%d\n",3*ans); Wu     return 0; -}

TYVJ1939 Jade Toad Hall

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.