City Game

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 5984    Accepted Submission(s): 2569

Problem Description
Bob 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.
 
Input
The 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.
 
Output
For 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

题解:上题的强化版,dp记录的当前连续的f长度;相当于长方形的高;接下来就是上题的子问题了;

刚开始一个一个字符输入的wa了,最后改成字符串输入才对;

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
const int INF=0x3f3f3f3f;
#define mem(x,y) memset(x,y,sizeof(x))
#define SI(x) scanf("%d",&x)
#define PI(x) printf("%d",x)
#define SD(x,y) scanf("%lf%lf",&x,&y)
#define P_ printf(" ")
const int MAXN=;
typedef long long LL;
char mp[MAXN][MAXN];
int l[MAXN],r[MAXN],s[MAXN];
int dp[MAXN][MAXN];
int main(){
int T,N,M;
SI(T);
char ch[];
while(T--){
SI(N);SI(M);
for(int i=;i<=N;i++){
for(int j=;j<=M;j++){
scanf("%s",ch);
mp[i][j]=ch[];
}
}
int area=;
mem(dp,);
for(int i=;i<=N;i++){
s[]=s[M+]=-;
for(int j=;j<=M;j++){
if(mp[i][j]=='F')dp[i][j]=dp[i-][j]+;
s[j]=dp[i][j];
l[j]=j;r[j]=j;
}
for(int j=;j<=N;j++){
while(s[l[j]-]>=s[j])
l[j]=l[l[j]-];
}
for(int j=N;j>=;j--){
while(s[r[j]+]>=s[j])
r[j]=r[r[j]+];
}
for(int j=;j<=N;j++){
area=max(area,s[j]*(r[j]-l[j]+));
}
}
printf("%d\n",area*);
}
return ;
}

City Game(动态规划)的更多相关文章

  1. HDU 1505 Largest Rectangle in a Histogram &amp;&amp; HDU 1506 City Game(动态规划)

    1506意甲冠军:给你一个连续的直方图(拼贴底部长度1).求连续基质区. 对每一个直方图,分别向左向右进行扩展. #include<cstdio> #include<stdlib.h ...

  2. 转载:hdu 动态规划题集

    1.Robberies 连接 :http://acm.hdu.edu.cn/showproblem.php?pid=2955     背包;第一次做的时候把概率当做背包(放大100000倍化为整数): ...

  3. TSP(旅行者问题)——动态规划详解(转)

    1.问题定义 TSP问题(旅行商问题)是指旅行家要旅行n个城市,要求各个城市经历且仅经历一次然后回到出发城市,并要求所走的路程最短. 假设现在有四个城市,0,1,2,3,他们之间的代价如图一,可以存成 ...

  4. poj 动态规划题目列表及总结

    此文转载别人,希望自己能够做完这些题目! 1.POJ动态规划题目列表 容易:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 11 ...

  5. poj动态规划列表

    [1]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 13 ...

  6. POJ 动态规划题目列表

    ]POJ 动态规划题目列表 容易: 1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, 1189, 1208, 1276, 1322 ...

  7. F - Free DIY Tour(动态规划,搜索也行)

    这道题可用动态规划也可以用搜索,下面都写一下 Description Weiwei is a software engineer of ShiningSoft. He has just excelle ...

  8. poj 动态规划的主题列表和总结

    此文转载别人,希望自己可以做完这些题目. 1.POJ动态规划题目列表 easy:1018, 1050, 1083, 1088, 1125, 1143, 1157, 1163, 1178, 1179, ...

  9. hdu 动态规划(46道题目)倾情奉献~ 【只提供思路与状态转移方程】(转)

    HDU 动态规划(46道题目)倾情奉献~ [只提供思路与状态转移方程] Robberies http://acm.hdu.edu.cn/showproblem.php?pid=2955      背包 ...

随机推荐

  1. 这些年,我收集的JavaScript代码(一)

    一.取URL中的参数 function getParameterByName(name) { var match = RegExp('[?&]' + name + '=([^&]*)' ...

  2. ORACLE RAC中的oc4j和gsd资源以及RAC相关的进程

    1.RAC相比单实例数据库多出的进程: LMS - Gobal Cache Service Process 全局缓存服务进程 LMD - Global Enqueue Service Daemon 全 ...

  3. iOS多线程总结(一)NSThread

    多线程,简而言之,就是提供代码的多个执行路径,对于App性能和用户体验都有着至关重要的意义.在iOS开发中,Apple提供了不同的技术支持多线程编程,主要有NSThread.NSOperationQu ...

  4. action中实现对批量文件上传的封装

    如今,文件(尤其是图片)上传,在前后台的应用相当普遍,上传头像.共享资料等已成为最基本应用.我们很希望通过一个万能的封装方法来实现一劳永逸的效果. 接下来,就来为大家介绍具体实现. 首先,我们需要一个 ...

  5. ios 开发 常见问题解决 (持续更新)

    1.使用cocoaPods引用第三方类库,报错:file not found   . 解决方案:设置 Project->Info->Configurations之后  clear ,然后再 ...

  6. C#性能优化实践【转】

    性能主要指两个方面:内存消耗和执行速度.性能优化简而言之,就是在不影响系统运行正确性的前提下,使之运行地更快,完成特定功能所需的时间更短. 本文以.NET平台下的控件产品MultiRow为例,描述C# ...

  7. 微软Code Hunt答案(00-05)——沉迷娱乐的我

    昨天看到微软出的网游Code Hunt.o(∩_∩)o...哈哈,还不好好玩一吧,个人感觉不是一个模块比一个模块难的,Code Hunt是按功能划分.所以不要怕自己做不来.由于不同人特长不一样. 像A ...

  8. struts2整合json要注意的问题

    昨天struts2整合json,一直出错: There is no Action mapped for namespace / and action name ... HTTP Status 404 ...

  9. JSP 文件上传下载系列之二[Commons fileUpload]

    前言 关于JSP 文件上传的基础和原理在系列一中有介绍到. 这里介绍一个很流行的组件commons fileupload,用来加速文件上传的开发. 官方的介绍是:  让添加强壮,高性能的文件到你的se ...

  10. Effective C++ 条款18

    让接口easy被正确使用,不easy被误用 如题目,我们自己的程序接口是面向用户的,程序的目的不可是解决这个问题,并且要让用户easy使用.所以.必须保证我们的程序接口具有非常强的鲁棒性. 怎么保证接 ...