HDU1505-City Game(记忆化搜索)
City Game
http://acm.hdu.edu.cn/showproblem.php?pid=1505
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.
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.
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
解题心得:
1、这个题是POJ2559-Largest
Rectangle in a Histogram的升级版,关于左右状态的转移就不说了,前面那个链接里面说了。就说说怎么把这个题和前面那个题联系起来解决。
2、这个题有一个处理技巧就是将同一列里面连续的'F'个数加起来,就变成了列宽,在一个’F‘的左方列宽大于'F'的才能够进行left的状态转移,右方同理,这样得到的有left和right还有列宽就可以直接得到面积了,这个技巧的启示来自于这个题:矩阵求最大和。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1100;
char maps[maxn][maxn];
int h[maxn][maxn];
int r[maxn],l[maxn];
int n,m;
int Max = 0; void get_leftEdge(int x)
{
for(int j=2; j<=m; j++)
{
if(h[x][j-1] >= h[x][j])
l[j] = l[j-1];
}
} void get_rightEdge(int x)
{
for(int j=m-1; j>=1; j--)
{
if(h[x][j+1] >= h[x][j])
r[j] = r[j+1];
} } void get_ans(int x)
{
for(int j=1; j<=m; j++)
if(Max < h[x][j] * (r[j] - l[j] + 1))
Max = h[x][j] * (r[j] - l[j] + 1);
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
Max = 0;
memset(h,0,sizeof(h));
scanf("%d%d",&n,&m);
for(int i=1; i<=n; i++)
{
for(int j=1; j<=m; j++)
{
scanf("%s",&maps[i][j]);
if(maps[i][j] == 'F')
{
h[i][j] = h[i-1][j] + 1;
}
l[j] = r[j] = j;
}
get_leftEdge(i);//处理maps[i][j]在i行左方的边界
get_rightEdge(i);//右方边界
get_ans(i);
}
printf("%d\n",Max*3);
}
}
HDU1505-City Game(记忆化搜索)的更多相关文章
- hdu 4856 Tunnels (记忆化搜索)
Tunnels Time Limit: 3000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- hdu 1078 FatMouse and Cheese (dfs+记忆化搜索)
pid=1078">FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/ ...
- poj 3249 Test for Job (DAG最长路 记忆化搜索解决)
Test for Job Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 8990 Accepted: 2004 Desc ...
- UVA 825 Walking on the Safe Side(记忆化搜索)
Walking on the Safe Side Square City is a very easy place for people to walk around. The two-way ...
- HDU - 1078 FatMouse and Cheese (记忆化搜索)
FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension ...
- HDU1078记忆化搜索
FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- kuangbin专题十二 HDU1078 FatMouse and Cheese )(dp + dfs 记忆化搜索)
FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- 记忆化搜索:HDU1078-FatMouse and Cheese(记忆化搜索)
FatMouse and Cheese Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- P - FatMouse and Cheese 记忆化搜索
FatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension ...
- hdu1078 FatMouse and Cheese(记忆化搜索)
转载请注明出处:http://blog.csdn.net/u012860063 题目链接:pid=1078" target="_blank">http://acm. ...
随机推荐
- <ganglia+nagios>rhel6.5
由于linux下的office和win下有所区别,我只能把linux下的.dot文件打包成pdf,粘贴发送标出来,但有些图片还是没办法发表,要是有朋友感兴趣的话,可加我qq 215687833具体的文 ...
- HTML5 有哪些不同类型的存储?
HTML 5 支持本地存储,在之前版本中是通过 Cookie 实现的.HTML5 本地存储速度快而且安全. 有两种不同的对象可用来存储数据: localStorage 适用于长期存储数据,浏览器关闭后 ...
- db2一些简单操作及错误记录
操作: 删除主键: alter table tablename drop parimary key 添加主键: alter table tablename add primary key(colum ...
- Get和Post的请求
get post请求 <form method="post","get", action="a.ashx"> <input ...
- DRF之视图组件
不断的优化我们写的程序,是每个程序员必备的技能和职业素养,也是帮助我们成长的非常重要的手段. 使用serializer进行put接口设计 根据规范,PUT接口用来定义用户对数据修改的逻辑,也就是upd ...
- webpake-node-sass 报错
问题描述: npm run dev 就报错,在安装node-sass错误 解决方法 : 找到node_modules下的node-sass文件,进入,如果没有vendor文件夹,就创建一个空文件夹,命 ...
- Python开发环境Wing IDE如何进行命令行调试
Wing IDE专业的调试探针提供了一种强大的方法来发现和解决复杂的错误.这很像Python Shell但允许用户直接参与进已经暂停的调试程序中: 通过键入在刚才发生异常的地方键入下列数值进行尝试: ...
- c#中反射技术在Unity中的运用
反射技术给类赋值的好处就是可以简化代码,封装的好处就显而易见了.最直接的用途就是用在在显示配置文件的时候,个人习惯性做法是做一个VO来存储需要的数据,其代码如下: internal class Bas ...
- 【iOS学习笔记】改变状态栏字体颜色
Step1. info.plist中设置UIViewControllerBasedStatusBarAppearance为NO Step2. AppDelegate.m中添加 - (BOOL)appl ...
- cocos2d-x 学习资料汇总
cocos2d-x配置问题 - 我要飞的更高 - 博客频道 - CSDN.NET Cocos2d-x win7 + vs2010 配置图文详解(亲测) - 子龙山人 - 博客园 WINDONWS7+V ...