City Game(最大子矩阵)
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[] 数组,
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
#define MX 1005
int n,m;
int h[MX][MX];
int L[MX][MX];
int R[MX][MX];
char mp[MX][MX]; void set_h()
{
memset(h,,sizeof(h));
for (int i=;i<=m;i++)
if (mp[][i]=='F')
h[][i]=;
for (int i=;i<=n;i++)
for (int j=;j<=m;j++)
if (mp[i][j]=='F')
h[i][j]=h[i-][j]+;
} void set_LR()
{
for (int i=;i<=n;i++)
{
for (int j=;j<=m;j++)
{
L[i][j]=j;
if (h[i][j]==) continue;
while (h[i][L[i][j]-]>=h[i][j])
L[i][j]=L[i][L[i][j]-];
}
}
for (int i=;i<=n;i++)
{
for (int j=m;j>=;j--)
{
R[i][j]=j;
if (h[i][j]==) continue;
while (h[i][R[i][j]+]>=h[i][j])
R[i][j]=R[i][R[i][j]+];
}
}
} int main()
{
int t;
cin>>t;
while (t--)
{
scanf("%d%d",&n,&m);
for (int i=;i<=n;i++)
{
for (int j=;j<=m;j++)
{
char sss[];
scanf("%s",sss);
mp[i][j]=sss[];
}
}
set_h();
set_LR();
int ans = ;
for (int i=;i<=n;i++)
{
for (int j=;j<=m;j++)
{
int area = (R[i][j]-L[i][j]+)*h[i][j];
if (area>ans) ans = area;
}
}
printf("%d\n",ans*);
}
return ;
}
City Game(最大子矩阵)的更多相关文章
- la----3695 City Game(最大子矩阵)
Bob is a strategy game programming specialist. In his new city building game the gaming environment ...
- DP:0
小故事: A * "1+1+1+1+1+1+1+1 =?" * A : "上面等式的值是多少" B : *计算* "8!" A *在上面等式 ...
- UVa LA 3029 City Game 状态拆分,最大子矩阵O(n2) 难度:2
题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...
- POJ 1964&HDU 1505&HOJ 1644 City Game(最大0,1子矩阵和总结)
最大01子矩阵和,就是一个矩阵的元素不是0就是1,然后求最大的子矩阵,子矩阵里的元素都是相同的. 这个题目,三个oj有不同的要求,hoj的要求是5s,poj是3秒,hdu是1秒.不同的要求就对应不同的 ...
- City Game UVALive - 3029(悬线法求最大子矩阵)
题意:多组数据(国外题好像都这样),每次n*m矩形,F表示空地,R表示障碍 求最大子矩阵(悬线法模板) 把每个格子向上延伸的空格看做一条悬线 以le[i][j],re[i][j],up[i][j]分别 ...
- 十月例题F题 - City Game
F - City Game Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Bob is a st ...
- 【巧妙预处理系列】【UVA1330】City game
最大子矩阵(City Game, SEERC 2004, LA 3029) 给定一个m×n的矩阵,其中一些格子是空地(F),其他是障碍(R).找出一个全部由F组成的面积最大的子矩阵,输出其面积乘以3后 ...
- hdu 1505(最大子矩阵)
City Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- ACM 中 矩阵数据的预处理 && 求子矩阵元素和问题
我们考虑一个$N\times M$的矩阵数据,若要对矩阵中的部分数据进行读取,比如求某个$a\times b$的子矩阵的元素和,通常我们可以想到$O(ab)$的遍历那个子矩阵,对它的各 ...
随机推荐
- hibernate.cfg.xml配置文件对关联关系的书写技巧!
以Department(部门类)和User(用户类)作为例子: 类图如下: 一般hibernate.cfg.xml的配置文件开头都是如下: <?xml version="1.0&quo ...
- WEB-INF有关的目录路径问题总结
1.资源文件只能放在WebContent下面,如 CSS,JS,image等.放在WEB-INF下引用不了. 2.页面放在WEB-INF目录下面,这样可以限制访问,提高安全性.如JSP,html 3. ...
- ambari修改admin密码
https://community.hortonworks.com/questions/449/how-to-reset-ambari-admin-password.html 1) Postgres ...
- [转]js模块化编程之彻底弄懂CommonJS和AMD/CMD!
原文: https://www.cnblogs.com/chenguangliang/p/5856701.html ------------------------------------------ ...
- PHP面试题遇到的几个坑。...面壁ing
1.指针悬挂问题 $array = [1, 2, 3]; echo implode(',', $array), "\n"; foreach ($array as &$val ...
- 数据库中存在0,1,2.....或者1,null,2 排序时让0或者null在最后的sql语句
select * from yryz_products_t order by isnull(sort),sort; select * from yourtable order by cast ...
- 性能测试之Tomcat优化
1.Tomcat最大连接数等配置 Tomcat的server.xml中Context元素的以下参数都是什么意思? <Connector port="8080"maxThr ...
- 24.JAVA编程思想——违例差错控制
24.JAVA编程思想--违例差错控制 Java 的基本原理就是"形式错误的代码不会执行". 与C++类似,捕获错误最理想的是在编译期间,最好在试图执行程序曾经.然而.并不是全部错 ...
- selenium从入门到应用 - 6,EventFiringWebDriver和监听器
本系列所有代码 https://github.com/zhangting85/simpleWebtest 本文将介绍一个Java+TestNG+Maven+Selenium的web自动化测试脚本环境下 ...
- python--pipe
1.pipe 除了使用队列外,还可以使用管道在进程间执行消息传递 pipe([]duplex) 在进程间创建一条管道,并返回元组(conn1,conn2),其中conn1和conn2是表示管道两端的C ...