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 – 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.

Input

The first line of the input contains an integer K – 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 – reserved unit 
F – free unit 
In the end of each area description there is a separating line.

Output

For 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
 #include<cstdio>
#include<iostream>
//#include<cstring>
//include<algorithm>
//#include<cmath>
//#include<vector>
//#include<queue>
//#include<set>
#define INF 0x3f3f3f3f
#define N 1005
#define re register
#define Ii inline int
#define Il inline long long
#define Iv inline void
#define Ib inline bool
#define Id inline double
#define ll long long
#define Fill(a,b) memset(a,b,sizeof(a))
#define R(a,b,c) for(register int a=b;a<=c;++a)
#define nR(a,b,c) for(register int a=b;a>=c;--a)
#define Min(a,b) ((a)<(b)?(a):(b))
#define Max(a,b) ((a)>(b)?(a):(b))
#define Cmin(a,b) ((a)=(a)<(b)?(a):(b))
#define Cmax(a,b) ((a)=(a)>(b)?(a):(b))
#define D_e(x) printf("\n&__ %d __&\n",x)
#define D_e_Line printf("-----------------\n")
#define D_e_Matrix for(re int i=1;i<=n;++i){for(re int j=1;j<=m;++j)printf("%d ",g[i][j]);putchar('\n');}
using namespace std;
//The Code Below Is Bingoyes's Function Forest.
Ii read(){
int s=,f=;char c;
for(c=getchar();c>''||c<'';c=getchar())if(c=='-')f=-;
while(c>=''&&c<='')s=s*+(c^''),c=getchar();
return s*f;
}
Iv print(ll x){
if(x<)putchar('-'),x=-x;
if(x>)print(x/);
putchar(x%^'');
}
/*
Iv Floyd(){
R(k,1,n)
R(i,1,n)
if(i!=k&&dis[i][k]!=INF)
R(j,1,n)
if(j!=k&&j!=i&&dis[k][j]!=INF)
Cmin(dis[i][j],dis[i][k]+dis[k][j]);
}
Iv Dijkstra(int st){
priority_queue<int>q;
R(i,1,n)dis[i]=INF;
dis[st]=0,q.push((nod){st,0});
while(!q.empty()){
int u=q.top().x,w=q.top().w;q.pop();
if(w!=dis[u])continue;
for(re int i=head[u];i;i=e[i].nxt){
int v=e[i].pre;
if(dis[v]>dis[u]+e[i].w)
dis[v]=dis[u]+e[i].w,q.push((nod){v,dis[v]});
}
}
}
Iv Count_Sort(int arr[]){
int k=0;
R(i,1,n)
++tot[arr[i]],Cmax(mx,a[i]);
R(j,0,mx)
while(tot[j])
arr[++k]=j,--tot[j];
}
Iv Merge_Sort(int arr[],int left,int right,int &sum){
if(left>=right)return;
int mid=left+right>>1;
Merge_Sort(arr,left,mid,sum),Merge_Sort(arr,mid+1,right,sum);
int i=left,j=mid+1,k=left;
while(i<=mid&&j<=right)
(arr[i]<=arr[j])?
tmp[k++]=arr[i++]:
(tmp[k++]=arr[j++],sum+=mid-i+1);//Sum Is Used To Count The Reverse Alignment
while(i<=mid)tmp[k++]=arr[i++];
while(j<=right)tmp[k++]=arr[j++];
R(i,left,right)arr[i]=tmp[i];
}
Iv Bucket_Sort(int a[],int left,int right){
int mx=0;
R(i,left,right)
Cmax(mx,a[i]),++tot[a[i]];
++mx;
while(mx--)
while(tot[mx]--)
a[right--]=mx;
}
*/
int a[N][N];ll s[N][N];
Il Maximum_Submatrix(int n,int m){
ll ans=;
R(i,,n)
R(j,,m){
char ch;
cin>>ch;
s[i][j]=s[i-][j]+s[i][j-]-s[i-][j-]+((ch=='F')?:-INF);//Matrix prefix sum.
}
R(i,,n)
R(j,i,n){
ll sum=;
R(k,,m)
Cmin(sum,s[j][k]-s[i-][k]),Cmax(ans,s[j][k]-s[i-][k]-sum);
}
return ans;
}
#define Outprint(x) print(x),putchar('\n');
int main(){
int T=read();
while(T--){
int n=read(),m=read();
ll ans=Maximum_Submatrix(n,m);
ans*=;//Convert area to money.
Outprint(ans);
}
return ;
}
/*
Note:
Get the maximum submatrix as the area.
Error:
Rember to add 'return'(especially in 'inline long long').
*/

最新文章

  1. MongoVUE1.6.9破解启动提示System.ArgumentException: 字体“Courier New”不支持样式“Regular”
  2. SubSonic3.0使用外连接查询时查询不出数据的问题修改
  3. 关于prototype和__proto__ 以及 constructor的文字总结
  4. UITabBarController常见代理方法的使用
  5. windows下使用vim+ctags+taglist
  6. http://www.cnblogs.com/Matrix54/archive/2012/05/03/2481260.html
  7. 要件审判九步法及其基本价值 z
  8. Apache服务器配置默认首页文件名和网站路径
  9. 快速调试的VS设置
  10. 【译】 AWK教程指南 11递归程序
  11. WebApi异常
  12. Directx11学习笔记【二十二】 用高度图实现地形
  13. 在Windows上使用Ubuntu共享的打印机
  14. WPF Popup全屏 弹出方法。解决只显示75%的问题。
  15. 更改 Ubuntu默认Python版本的问题
  16. Hdoj 1905.Pseudoprime numbers 题解
  17. java ee期末项目相关
  18. Mysql系列二:Mysql 开发标准规范
  19. 关于 RabbitMQ 的 Dead-Letters-Queue “死信队列”
  20. jsp页面中日期的格式化

热门文章

  1. HTTP状态详解
  2. 记一篇Python学习的简易版教程
  3. threading学习
  4. 编写高质量代码改善C#程序的157个建议——建议27:在查询中使用Lambda表达式
  5. XE中FMX操作ListBox,添加上千条记录(含图片)
  6. 合成(Composite)模式
  7. 关于.net DateTime 的一些事儿
  8. IOS 防坑指南
  9. Jquery queue实例
  10. asp.net get图