Maximum child matrix (City game) seerc 2004, la 3029
I finally understood the examples in the white book after reading two classes. The concept of DP.
During scanning, maintain the number of spaces that can be raised up, the maximum number of left to left, and the number of right to left.
So you only need to scan it once to get the answer = up * (right-left + 1)
When I define the left array, it conflicts with iostream.
#include<cstdio>#include<cstring>#include<string>#include<queue>#include<algorithm>#include<map>#include<stack>//#include<iostream>#include<list>#include<set>#include<cmath>#define INF 0x7fffffff#define eps 1e-8#define LL long long#define PI 3.141592654#define CLR(a,b) memset(a,b,of(a))#define FORi(n) for(int i=0;i<n;i++)#define FORj(n) for(int j=0;j<n;j++)#define FORk(n) for(int k=0;k<n;k++)#define debug puts("==fuck==")#define acfun std::ios::sync_with_stdio(false)#define SIZE 1000+10using namespace std;bool g[SIZE][SIZE];int up[SIZE][SIZE];int left[SIZE][SIZE];int right[SIZE][SIZE];int main(){ int n,m; int t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); FORi(n) FORj(m) { char ch; scanf("%c",&ch); while(ch!='R'&&ch!='F') scanf("%c",&ch); if(ch=='R')g[i][j]=1; else g[i][j]=0; } int ans=0; FORi(n) { int lo=-1,ro=m; FORj(m) { if(g[i][j]) up[i][j]=left[i][j]=0,lo=j; else { if(i==0) { up[i][j]=1; left[i][j]=lo+1; } else { up[i][j]=up[i-1][j]+1; left[i][j]=max(left[i-1][j],lo+1); } } } for(int j=m-1;j>=0;j--) { if(g[i][j]) right[i][j]=m,ro=j; else { if(i==0) right[i][j]=ro-1; else right[i][j]=min(right[i-1][j],ro-1); ans=max(ans,up[i][j]*(right[i][j]-left[i][j]+1)); } } }// FORi(n)// {// FORj(m)// printf("%3d ",up[i][j]*(right[i][j]-left[i][j]+1));// printf("\n");// } printf("%d\n",ans*3); }}
HDU 1505 City game