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)$的遍历那个子矩阵,对它的各 ...
随机推荐
- iOS:自定义模态动画 --UIPresentationController
UIPresentationController :展示控制器,是iOS8的一个新特性,用来展示模态窗口的.它是所有模态控制器的管理者. 即: 1> 管理所有Modal出来的控制器 2> ...
- 机器学习第1课:引言(Introduction)
1.前言 Machine Learning(机器学习)是研究计算机怎样模拟或实现人类的学习行为,以获取新的知识或技能,重新组织已有的知识结构使之不断改善自身的性能. 它是人工智能的核心,是使计算机具有 ...
- ios开发中APP底部上滑不能调出如WiFi、蓝牙、播放等的设置页面的解决的方法
在开发的APP中我们通常通过手动底部上滑来调出WiFi.蓝牙.飞行模式等的设置页面.有时我们开发的APP无法调出. 解决的方法: 进入iPhone "设置" --> &quo ...
- How to support both ipv4 and ipv6 address for JAVA code.
IPv6 have colon character, for example FF:00::EEIf concatenate URL String, IPv6 URL will like: http: ...
- eclispe查看jdk源码后特别卡顿导致未响应解决
第一步:Eclipse -> Preferences -> General -> Startup and Shutdown.不要勾选 RSE UI. 第二步:Eclipse -> ...
- vs2012_error C2061: 语法错误: 标识符“uint64_t”
加入头文件#include <stdint.h>
- selenium从入门到应用 - 4,页面对象设计模式的实现
本系列所有代码 https://github.com/zhangting85/simpleWebtest 本文将介绍一个Java+TestNG+Maven+Selenium的web自动化测试脚本环境下 ...
- close_wait状态的产生原因及解决(转)
最近测试环境server由于需要与大量的后台server交互,今天突然发现有大量的close_wait产生,于是仔细研究了一下: 如果我们的服务器程序处于CLOSE_WAIT状态的话,说明套接字是被动 ...
- @Autowired @Transaction @Service同时出现。
对于@Autowired,如果只写这些,肯定是根据类型自动装配这个没问题. @Service public class AcRoleServiceImpl implements AcRoleServi ...
- Android中database所在文件夹路径(9.6)
1 sd----->data---->对应app---->databases----->创建的db 2 push到pc上,可以使用GUI工具SQLiteSpy直接查看datab ...