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)$的遍历那个子矩阵,对它的各 ...
随机推荐
- Java算法题:兔子问题
题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第四个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 解题思路: public int exp(int ...
- k8s restful API 结构分析
k8s的api-server组件负责提供restful api访问端点, 并且将数据持久化到etcd server中. 那么k8s是如何组织它的restful api的? 一, namespaced ...
- Elasticsearch教程(八) elasticsearch delete 删除数据(Java)
Elasticsearch的删除也是很灵活的,下次我再介绍,DeleteByQuery的方式.今天就先介绍一个根据ID删除.上代码. package com.sojson.core.elasticse ...
- Javascript中的回调函数和匿名函数的回调
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Mybatis 存在多个日志时设置日志
mybatis默认使用log4j,当有self4j这个日志jar包存在时会无法打印sql,请移除或者在工程启动时显示设置mybatis使用的日志类 log4j.logger.org.apache.ib ...
- [j2ee]java中的xml操作
一.XML简单介绍 xml是可扩展标记语言,主要用来标记数据.定义数据类型,很适合万维网传输. xml特点: xml是一种标记语言.非常类似HTML xml的设计宗旨是数据传输,而不是显示数 ...
- Win7 设置、访问共享文件夹
一.设置共享文件夹 右键点击文件夹,打开“属性”窗口,选择“共享”选项卡 点击“共享”按钮,打开“文件共享”窗口,在下拉列表中选择账户,点“添加”,最后点“共享”按钮. 二.访问 \\192.168. ...
- Java IO、网络编程、NIO、Netty、Hessian、RPC、RMI的学习路线
好久没看Java IO这块的内容,感觉都快忘得差不多了.平成编程也没有设计到太多的Java基础知识,所以这里希望可以抽点时间回顾一下,让艾宾浩斯记忆曲线不要下降的太快. 回顾这个主要还是以总结为主,能 ...
- CSDN开源夏令营 基于Compiz的switcher插件设计与实现之前期准备 git的简单使用
因为项目的代码须要上传到git上.就须要学习一下git的使用了. 我初步接触了一下git,准备用此帖来记录git的学习,此帖会随着我对git了解的深入动态更新. 一.GIT的介绍 1.概述:git是一 ...
- 如何提高Linux下块设备IO的整体性能?
编辑手记:本文主要讲解Linux IO调度层的三种模式:cfp.deadline和noop,并给出各自的优化和适用场景建议. 作者简介: 邹立巍 Linux系统技术专家.目前在腾讯SNG社交网络运营部 ...