HDU 1505 City game

Source: Internet
Author: User

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1505

First, process the bottom-up height of each row and then process the left and right sides.

 1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #define maxn 1001 5 using namespace std; 6  7 int t; 8 int n,m; 9 int a[maxn][maxn];10 int l[maxn],r[maxn];11 12 int main()13 {14     scanf("%d",&t);15     while(t--)16     {17         scanf("%d%d",&n,&m);18         getchar();19         memset(a,0,sizeof(a));20         for(int i=1; i<=n; i++)21         {22             for(int j=1; j<=m; j++)23             {24                 char s[10];25                 scanf("%s",s);26                 if(s[0]==‘F‘) a[i][j]=a[i-1][j]+1;27                 else a[i][j]=0;28             }29         }30         int max1=-1;31         for(int i=1; i<=n; i++)32         {33             a[i][0]=a[i][m+1]=-1;34             for(int j=1; j<=m; j++)35                 l[j]=r[j]=j;36             for(int j=1; j<=m; j++)37             {38                 while(a[i][j]<=a[i][l[j]-1]) l[j]=l[l[j]-1];39             }40             for(int j=m; j>=1; j--)41             {42                 while(a[i][j]<=a[i][r[j]+1]) r[j]=r[r[j]+1];43             }44             for(int j=1; j<=m; j++)45             {46                 int ans=a[i][j]*(r[j]-l[j]+1);47                 if(ans>max1)48                     max1=ans;49             }50         }51         printf("%d\n",max1*3);52     }53     return 0;54 }
View code

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.