F-city Game

Source: Internet
Author: User

LA 3029

To find the maximum sub-matrix problem, mainly consider the enumeration method, the direct enumeration is definitely not possible, because the number of sub-matrices of a large matrix is a number of points, so you should consider before the enumeration of the scanning work.

Use the Left,right,up array to record the maximum distance from the i,j position to the left, right, and above, then end with just enumerating each block (Right-left) *up

#include <iostream>#include<cstdio>#include<cstring>#defineM (a) memset (A,0,sizeof (a))Const intmaxn=1e3+Ten;CharA[MAXN][MAXN];intUP[MAXN][MAXN],RIGHT[MAXN][MAXN],LEFT[MAXN][MAXN];intM,n;intMaxintX1,intx2) {    returnX1>x2?x1:x2;}intMinintX1,intx2) {    returnX1>x2?x2:x1;}voidInit () {scanf ("%d%d",&m,&N);  for(intI=1; i<=m; i++)         for(intj=1; j<=n; J + +) std::cin>>A[i][j];    M (UP);    M (right);        M (left);  for(intI=1; i<=m; i++)    {        intlo=0;  for(intj=1; j<=n; J + +)        {            if(a[i][j]=='R') {Up[i][j]=0; LEFT[I][J]=0; Lo=J; }            Else            {                if(i==1) {Up[i][j]=1; LEFT[I][J]=lo+1; }                Else{Up[i][j]=up[i-1][j]+1; LEFT[I][J]=max (lo+1, left[i-1][j]); }            }        }        intro=n+1;  for(intJ=n; j>=1; j--)        {            if(a[i][j]=='R') {Right[i][j]=n+1; Ro=J; }            Else            {                if(i==1) {Right[i][j]=ro-1; }                Else{Right[i][j]=min (ro-1, right[i-1][j]); }            }        }    }}voidWork () {intans=-1e9;  for(intI=1; i<=m; i++)         for(intj=1; j<=n; J + +) {ans=max (ans, (right[i][j]-left[i][j]+1)*Up[i][j]); } printf ("%d\n",3*ans);}intMain () {intT; scanf ("%d",&T);  while(t--) {Init ();    Work (); }    return 0;}
View Code

F-city Game

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.