hdu 1505

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1505

思路:完全就是hdu 1506的加强版,只要取定第i行,这样就可以用1506的方法来做了,最后加个for循环就行了;

View Code
 1 #include<iostream>
 2 #include<algorithm>
 3 const int N=1100;
 4 using namespace std;
 5 int l[N][N],r[N][N],h[N][N];
 6 char map[N][N];
 7 
 8 int main(){
 9     int _case;
10     scanf("%d",&_case);
11     while(_case--){
12         int n,m;
13         scanf("%d%d",&n,&m);
14         for(int i=1;i<=m;i++){
15             h[0][i]=0;
16         }
17         for(int i=1;i<=n;i++){
18             for(int j=1;j<=m;j++){
19                 scanf("%s",&map[i][j]);
20                 l[i][j]=j,r[i][j]=j;
21                 if(map[i][j]=='F'){
22                     h[i][j]=h[i-1][j]+1;
23                 }else if(map[i][j]=='R'){
24                     h[i][j]=0;
25                 }
26             }
27         }
28         int ans=0,Max=0;
29         for(int i=1;i<=n;i++){
30             h[i][0]=h[i][m+1]=-1;
31             for(int j=1;j<=m;j++){
32                 while(h[i][l[i][j]-1]>=h[i][j])
33                     l[i][j]=l[i][l[i][j]-1];
34             }
35             for(int j=m;j>=1;j--){
36                 while(h[i][r[i][j]+1]>=h[i][j])
37                     r[i][j]=r[i][r[i][j]+1];
38             }
39             for(int j=1;j<=m;j++){
40                 ans=(r[i][j]-l[i][j]+1)*h[i][j];
41                 Max=max(ans,Max);
42             }
43         }
44         printf("%d\n",3*Max);
45     }
46     return 0;
47 }
原文地址:https://www.cnblogs.com/wally/p/2953001.html