hdu 1505(最大子矩阵)
City Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6140 Accepted Submission(s): 2618
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.
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.
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.
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
0
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
const int N = ; int n,m;
char a[N][N];
int mp[N][N];
int L[N],R[N];
void input()
{
int i,j;
for(i=1; i<=n; i++)
for(j=1; j<=m; j++)
cin>>a[i][j];
for(i=1; i<=m; i++)
mp[0][i]=0;
for(i=1; i<=m; i++)
{
for(j=1; j<=n; j++)
{
if(a[j][i]=='F')
mp[j][i]=mp[j-1][i]+1;
else
mp[j][i]=0;
}
}
/*for(int i=1;i<=n;i++){ //test
for(int j=1;j<=m;j++){
printf("%d ",mp[i][j]);
}
printf("\n");
}*/
}
/*void input(){
memset(mp,0,sizeof(mp));
for(int i=1;i<=n;i++){
gets(a[i]);
for(int j=1;j<=m;j++){
if(i==1) { ///预处理mp
if(a[i][(j-1)*2]=='R') mp[i][j]=0;
if(a[i][(j-1)*2] =='F') mp[i][j]=1;
}else{
if(a[i-1][(j-1)*2]=='R') {
if(a[i][(j-1)*2] =='R') mp[i][j]=0;
if(a[i][(j-1)*2] =='F') mp[i][j]=1;
}
else {
if(a[i][(j-1)*2] =='R') mp[i][j]=0;
if(a[i][(j-1)*2] =='F') mp[i][j]+=mp[i-1][j]+1;
}
}
}
}
/*for(int i=1;i<=n;i++){ //test
for(int j=1;j<=m;j++){
printf("%d ",mp[i][j]);
}
printf("\n");
}*/
}*/
int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--){
scanf("%d%d",&n,&m);
getchar();
input();
int mx = -;
for(int k=;k<=n;k++){
L[]=;
R[m]=m;
for(int i=;i<=m;i++){ ///向右延伸
int t = i;
if(t>&&mp[k][i]<=mp[k][t-]) t = L[t-];
L[i] =t;
}
for(int i=m-;i>=;i--){
int t = i;
if(t<m&&mp[k][i]<=mp[k][t+]) t = R[t+];
R[i] = t;
}
for(int i=;i<=m;i++){
if((R[i]-L[i]+)*mp[k][i]>mx) mx = (R[i]-L[i]+)*mp[k][i];
}
}
printf("%d\n",mx*);
} }
hdu 1505(最大子矩阵)的更多相关文章
- HDU 1505 City Game (hdu1506 dp二维加强版)
F - City Game Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submi ...
- hdu 1505(dp求最大子矩阵)
题意:就是让你求出全由F组成的最大子矩阵. 分析:这是hdu 1506的加强版,只不过这道题变成了2维的,那我们就一行一行的来.具体的分析见1506的博客:http://www.cnblogs.com ...
- POJ 1964&HDU 1505&HOJ 1644 City Game(最大0,1子矩阵和总结)
最大01子矩阵和,就是一个矩阵的元素不是0就是1,然后求最大的子矩阵,子矩阵里的元素都是相同的. 这个题目,三个oj有不同的要求,hoj的要求是5s,poj是3秒,hdu是1秒.不同的要求就对应不同的 ...
- hdu 1559 最大子矩阵
最大子矩阵 Time Limit: 30000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
- hdu 1081(最大子矩阵和)
题目很简单,就是个最大子矩阵和的裸题,看来算法课本的分析后也差不多会做了.利用最大子段和的O(n)算法,对矩阵的行(或列)进行 i和j的枚举,对于第 i到j行,把同一列的元素进行压缩,得到一整行的一维 ...
- hdu 1559 最大子矩阵 (简单dp)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1559 #include <cstring> #include <cstdlib> ...
- HDU 1559 最大子矩阵 (DP)
题目地址:pid=1559">HDU 1559 构造二维前缀和矩阵.即矩阵上的点a[i][j]表示左上方的点为(0,0),右下方的点为(i,j)的矩阵的和.然后枚举每一个矩阵的左上方的 ...
- HDU 1505 Largest Rectangle in a Histogram && HDU 1506 City Game(动态规划)
1506意甲冠军:给你一个连续的直方图(拼贴底部长度1).求连续基质区. 对每一个直方图,分别向左向右进行扩展. #include<cstdio> #include<stdlib.h ...
- ACM HDU 1559 最大子矩阵
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1559 这道题 挺好的,当时想出解法的时候已经比较迟了.还是平时看得少. 把行与列都进行压缩.ans[i ...
随机推荐
- Linux之初试驱动20160613
这篇文章主要介绍一下Linux内核下的驱动结构与书写,以及介绍Linux下简单使用驱动的应用程序: 首先我们直接看使用驱动的简单应用程序: #include <sys/types.h> # ...
- JavaScript URL汉字编码转换
在使用url进行参数传递时,经常会传递一些中文名的参数或URL地址,在后台处理时会发生转换错误.在有些传递页面使用GB2312,而在接收页面使用UTF8,这样接收到的参数就可能会与原来发生不一致.使用 ...
- selenium测试-open chrome
通过selenium来打开浏览器测试之前,需要确认本地已安装相应的webdriver,本例以chrome为例. 1. 查看本地chrome版本,以此确认需要安装的webdriver版本 查看chrom ...
- rn初体验
react-native 需要的工具 .nodejs .rn cli .xcode and as ---------------- 打开终端,切换到根路径(mac中修改npm的默认安装来源) 一.op ...
- [LeetCode] 数组的最长连续数, O(n)解法
Longest Consecutive Sequence Given an unsorted array of integers, find the length of the longest con ...
- Web Api Action的筛选
web Api设置默认路由设置: 这种目标Action方法的选择有以下几轮: 1.针对 HTTP方法 进行筛选 2.针对参数类型,可以做参数约束 3.针对参数数量 另一种路由“api/{control ...
- java加载驱动
加载驱动方法 1.Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 2. DriverManager.r ...
- c# “XXX::Invoke”类型的已垃圾回收委托进行了回调。这可能会导致应用程序崩溃、损坏和数据丢失。向非托管代码传递委托时,托管应用程序必须让这些委托保持活动状态,直到确信不会再次调用它们。
症状描述如下: 如果将一个委托作为函数指针从托管代码封送到非托管代码,并且在对该委托进行垃圾回收后对该函数指针发出了一个回调,则将激活 callbackOnCollectedDelegate 托管调试 ...
- 版本号中Snapshot的含义
Maven中建立的依赖管理方式基本已成为Java语言依赖管理的事实标准,Maven的替代者Gradle也基本沿用了Maven的依赖管理机制.在Maven依赖管理中,唯一标识一个依赖项是由该依赖项的三个 ...
- Asp.Net Web Forms/MVC/Console App中使用Autofac
本来简单介绍了Autofac在Asp.Net Web Forms中的应用,后来又添加了mvc.控制台应用程序中使用Autofac,详情请看源码. ASP.NET Web Forms使用Autofac, ...