Bob is a strategy game programming specialist. In his new city building game the gaming environment is as follows: a city is built up by areas, in which there are streets, trees,factories and buildings. There is still some space in the area that is unoccupied. The strategic task of his game is to win as much rent money from these free spaces. To win rent money you must erect buildings, that can only be rectangular, as long and wide as you can. Bob is trying to find a way to build the biggest possible building in each area. But he comes across some problems �C he is not allowed to destroy already existing buildings, trees, factories and streets in the area he is building in.
Each area has its width and length. The area is divided into a grid of equal square units.The rent paid for each unit on which you're building stands is 3$.
Your task is to help Bob solve this problem. The whole city is divided into K areas. Each one of the areas is rectangular and has a different grid size with its own length M and width N.The existing occupied units are marked with the symbol R. The unoccupied units are marked with the symbol F.
Each area has its width and length. The area is divided into a grid of equal square units.The rent paid for each unit on which you're building stands is 3$.
Your task is to help Bob solve this problem. The whole city is divided into K areas. Each one of the areas is rectangular and has a different grid size with its own length M and width N.The existing occupied units are marked with the symbol R. The unoccupied units are marked with the symbol F.
InputThe first line of the input contains an integer K �C determining the number of datasets. Next lines contain the area descriptions. One description is defined in the following way: The first line contains two integers-area length M<=1000 and width N<=1000, separated by a blank space. The next M lines contain N symbols that mark the reserved or free grid units,separated by a blank space. The symbols used are:
R �C reserved unit
F �C free unit
In the end of each area description there is a separating line.
OutputFor each data set in the input print on a separate line, on the standard output, the integer that represents the profit obtained by erecting the largest building in the area encoded by the data set.Sample Input
2
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
5 5
R R R R R
R R R R R
R R R R R
R R R R R
R R R R R
Sample Output
45
0
// 题意:第一行测试组数T,然后 n ,m 代表矩阵大小 n行m列 ,只有 F 才能建,求最大子矩阵
有点复杂,但是,如果你做过 hdu1506 ,这题一下就想到了。
对于每行都建个 L[] , R[] 数组,
1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 using namespace std; 5 #define MX 1005 6 int n,m; 7 int h[MX][MX]; 8 int L[MX][MX]; 9 int R[MX][MX]; 10 char mp[MX][MX]; 11 12 void set_h() 13 { 14 memset(h,0,sizeof(h)); 15 for (int i=1;i<=m;i++) 16 if (mp[1][i]=='F') 17 h[1][i]=1; 18 for (int i=2;i<=n;i++) 19 for (int j=1;j<=m;j++) 20 if (mp[i][j]=='F') 21 h[i][j]=h[i-1][j]+1; 22 } 23 24 void set_LR() 25 { 26 for (int i=1;i<=n;i++) 27 { 28 for (int j=1;j<=m;j++) 29 { 30 L[i][j]=j; 31 if (h[i][j]==0) continue; 32 while (h[i][L[i][j]-1]>=h[i][j]) 33 L[i][j]=L[i][L[i][j]-1]; 34 } 35 } 36 for (int i=1;i<=n;i++) 37 { 38 for (int j=m;j>=1;j--) 39 { 40 R[i][j]=j; 41 if (h[i][j]==0) continue; 42 while (h[i][R[i][j]+1]>=h[i][j]) 43 R[i][j]=R[i][R[i][j]+1]; 44 } 45 } 46 } 47 48 int main() 49 { 50 int t; 51 cin>>t; 52 while (t--) 53 { 54 scanf("%d%d",&n,&m); 55 for (int i=1;i<=n;i++) 56 { 57 for (int j=1;j<=m;j++) 58 { 59 char sss[20]; 60 scanf("%s",sss); 61 mp[i][j]=sss[0]; 62 } 63 } 64 set_h(); 65 set_LR(); 66 int ans = 0; 67 for (int i=1;i<=n;i++) 68 { 69 for (int j=1;j<=m;j++) 70 { 71 int area = (R[i][j]-L[i][j]+1)*h[i][j]; 72 if (area>ans) ans = area; 73 } 74 } 75 printf("%d ",ans*3); 76 } 77 return 0; 78 }