la----3695 City Game(最大子矩阵)
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 file 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 file 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
代码 :
1 #include<cstdio>
2 #include<algorithm>
3 using namespace std;
4 const int maxn = 1000;
5 int sac[maxn][maxn];
6 int up[maxn][maxn],left[maxn][maxn],right[maxn][maxn];
7 int main()
8 {
9 int T;
10 scanf("%d",&T);
11 while(T--)
12 {
13 int m,n;
14 scanf("%d%d",&m,&n);
15 for(int i=0;i<m;i++)
16 {
17 for(int j=0;j<n;j++)
18 {
19 int ch=getchar();
20 while(ch!='F'&&ch!='R')
21 ch=getchar();
22 sac[i][j]=ch=='F'?0:1;
23 }
24 }
25 int ans=0;
26 for(int i=0;i<m;i++){
27 int lo=-1,ro=n;
28 for(int j=0;j<n;j++){
29 if(sac[i][j]==1)
30 {
31 up[i][j]=left[i][j]=0;
32 lo=j;
33 }
34 else
35 {
36 up[i][j]=i==0?1:up[i-1][j]+1;
37 left[i][j]=i==0?lo+1:max(left[i-1][j],lo+1);
38 }
39 }
40 for(int j=n-1;j>=0;j--)
41 {
42 if(sac[i][j]==1)
43 {
44 right[i][j]=n;
45 ro=j;
46 }
47 else
48 {
49 right[i][j]=i==0?ro-1:min(right[i-1][j],ro-1);
50 ans=max(ans,up[i][j]*(right[i][j]-left[i][j]+1));
51 }
52 }
53 }
54 printf("%dn",ans*3);
55 }
56 return 0;
57 }
- Spring Cloud构建微服务架构:服务消费(Feign)【Dalston版】
- React Native组件(四)TextInput组件解析
- struts2实现ajax校验的2种方法
- 单例对象
- Android+struts2+json方式模拟手机登录功能
- iOS 获取通讯录里边的电话号码AddressBook
- InvocationTargetException异常解析
- Spring Cloud构建微服务架构:服务注册与发现(Eureka、Consul)【Dalston版】
- java基础多线程之共享数据
- Spring Boot自动化配置的利弊及解决之道
- Java四种引用解析以及在Android的应用
- java基础之泛型
- java基础之反射
- 第四章 正则表达式回溯法原理
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- Codeforces Beta Round #3 C. Tic-tac-toe
- [记录] 数据库中,根据经纬度,查询距离最近的地点
- PAT (Basic Level) Practice (中文)1010 一元多项式求导 (25 分)
- R语言随机森林模型中具有相关特征的变量重要性
- PAT (Basic Level) Practice (中文)1009 说反话 (20 分)
- Codeforces Beta Round #8 A. Train and Peter
- Codeforces Round #559 (Div. 2)B. Expansion coefficient of the array
- Codeforces Beta Round #72 (Div. 1 Only)B. Doctor
- pygame游戏常用方法
- node-blog:用 node 搭建的个人开源博客
- 2018-2019 ICPC, NEERC, Southern Subregional Contest D. Garbage Disposal
- 「查缺补漏」JavaScript执行上下文-执行栈
- 树状数组 _ 求逆序数
- PAT (Basic Level) Practice (中文)1012 数字分类 (20 分)
- PAT (Basic Level) Practice (中文)1018 锤子剪刀布 (20 分)