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. u Calculate e

    问题陈述: 杭州电子科技大学 HANGZHOU DIANZI UNIVERSITY Online Judge Problem - 1012 问题解析: 简单题,注意输出格式.引入<iomaini ...

  2. 关于 java.io.IOException: open failed: EACCES (Permission denied)

    今天解决了一个问题,不得不来和大家分享.就是关于 java.io.IOException: open failed: EACCES (Permission denied)的问题,网上也有很多人把这个问 ...

  3. SQL Server 数据库文件 4 点注意

    1.数据库被分解成逻辑页面,每页8K,在每一个文件中页面从 0 --> x 连续编号: 2.可以通过 [database_id]   [file_id]   [page_id] 的形式引用页面: ...

  4. 移动网络山寨版(OpenBTS)【2】频段的故事

    OpenBTS 系统有两个看点.一个是无线收发,尤其是频段的处理,另一个是网络系统,尤其是替代传统的基站(BTS),基站控制器(BSC),移动控制中心(MSC),以及(HLR/VLR)的另类方案. 先 ...

  5. 重启VirtualBox里面的系统提示VT-x features locked or unavailable in MSR错误

    有次不小心设置了一下virtualbox里面的一些配置,然后启动系统时出现了如下提示 在网上找了一些资料尝试了一些方法偶然有一次成功 原来是自己把那个cpu个数设置成了2,改成1就好了,不知道为什么做 ...

  6. Flex中如何通过设置GridLines对象的horizontalAlternateFill样式交错显示LineSeries图表背景颜色的例子

    原文 http://blog.minidx.com/2008/11/27/1652.html 接下来的例子演示了Flex中如何通过设置GridLines对象的horizontalAlternateFi ...

  7. rsyslog 读日志文件 ,当rsyslog 中断时,也会丢数据

    rsyslog 日志服务器: [root@dr-mysql01 winfae_log]# grep scan0819 wj-proxy01-catalina.out.2016-08-19 [root@ ...

  8. poj1477---搭积木

    #include<stdio.h> #include<stdlib.h> int main() { int n,i; int bricks[55],set=0; while(s ...

  9. 加入商品分类信息,考虑用户所处阶段的 图模型 推荐算法 Rws(random walk with stage)

    场景: 一个新妈妈给刚出生的宝宝买用品,随着宝宝的长大,不同的阶段需要不同的物品. 这个场景中涉及到考虑用户所处阶段,给用户推荐物品的问题. 如果使用用户协同过滤,则需要根据购买记录,找到与用户处于同 ...

  10. #include <iomanip>

    1 setfill 2 setprecision 3 setw 1 setfill setfill( 'c' ) 设填充字符为c ▲setfill(char c) 用法 : 就是在预设宽度中如果已存在 ...