Similar to HDU 1506, a [I] [j] is used to represent the maximum height at the I height j position.
[Cpp]
# Include <stdio. h>
# Define N 1002
Int a [N] [N];
Int l [N], r [N];
Int n, m; www.2cto.com
Char ch [10];
_ Int64 max, ans;
Int main ()
{
Int T, I, j;
Scanf ("% d", & T );
While (T --)
{
Scanf ("% d", & n, & m );
For (I = 0; I <= m; I ++) a [0] [I] = 0;
For (I = 1; I <= n; I ++)
For (j = 1; j <= m; j ++)
{
Scanf ("% s", ch );
If (ch [0] = 'F ')
A [I] [j] = a [I-1] [j] + 1; // height handling
Else a [I] [j] = 0; // In case of 'r', the height is set to zero.
}
Max = 0;
For (I = 1; I <= n; I ++) // scan from the first line. Other implementations are almost the same as HDU 1506
{
A [I] [0] = a [I] [m + 1] =-1;
For (j = 1; j <= m; j ++)
L [j] = r [j] = j;
For (j = 1; j <= m; j ++)
While (a [I] [j] <= a [I] [l [j]-1])
L [j] = l [l [j]-1];
For (j = m; j> = 1; j --)
While (a [I] [j] <= a [I] [r [j] + 1])
R [j] = r [r [j] + 1];
For (j = 1; j <= m; j ++)
{
Ans = a [I] [j] * (r [j]-l [j] + 1) * 3;
If (max <ans) max = ans;
}
}
Printf ("% I64d \ n", max );
}
Return 0;
}