计算出对应的高度,一层一层的DP最大面积

City Game

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

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
Source
Southeastern Europe 2004
Recommend
zl
 1 #include <iostream>
 2 #include <cstring>
 3
 4 using namespace std;
 5
 6 char a[1100][1100];
 7 int b[1100][1100];
 8
 9 int l[1100],r[1100];
10
11 int main()
12 {
13     int k;
14     cin>>k;
15     while(k--)
16     {
17         memset(a,'R',sizeof(a));
18         memset(b,0,sizeof(b));
19         int m,n;
20         cin>>m>>n;
21         for(int i=1;i<=m;i++)
22             for(int j=1;j<=n;j++)
23         {
24             char c;  cin>>c;
25             if(c=='R'||c=='F')
26                 a[i][j]=c;
27         }
28
29         for(int j=1;j<=n;j++)
30         {
31             int high=1;
32             for(int i=1;i<=m;i++)
33             {
34                 if(a[i][j]=='R') {high=1;}
35                 else if(a[i][j]=='F')
36                 {
37                    b[i][j]=high;
38                    high++;
39                 }
40             }
41         }
42
43         int ans=0;
44         for(int i=1;i<=m;i++)
45         {
46
47             for(int k=1;k<=n;k++)
48                 l[k]=r[k]=k;
49
50             for(int j=n;j>=1;j--)
51                while(b[i][r[j]+1]>=b[i][j]&&(r[j]+1)<=n)
52                    r[j]=r[r[j]+1];
53
54             for(int j=1;j<=n;j++)
55                 while(b[i][l[j]-1]>=b[i][j]&&(l[j]-1)>0)
56                    l[j]=l[l[j]-1];
57
58             for(int j=1;j<=n;j++)
59             ans=max(ans,b[i][j]*(r[j]-l[j]+1));
60
61         }
62
63         cout<<ans*3<<endl;
64
65     }
66     return 0;
67 }

转载于:https://www.cnblogs.com/CKboss/archive/2013/05/18/3086177.html

HDOJ 1505 City Game相关推荐

  1. hdu 1505 City Game

    http://acm.hdu.edu.cn/showproblem.php?pid=1505 先处理每一行上每一个F为底往上所到达的高度,然后再左右处理. 1 #include <cstdio& ...

  2. 有趣的动态规划题目(一)

    文章目录 [HDOJ 2084.数塔] [HDOJ 1176.免费馅饼] [HDOJ 1864.最大报销额] [HDOJ 1003.Max Sum] [HDOJ 1506.Largest Rectan ...

  3. 杭电OJ分类题目(3)

    原题出处:HDOJ Problem Index by Type,http://acm.hdu.edu.cn/typeclass.php 杭电OJ分类题目(3) HDU Computational Ge ...

  4. 入门经典_Chap08_题解总结:极角扫描法 滑动窗口 单调队列 单调栈

    总结  本章主要关注一个重要的问题 – 单调队列和单调栈的使用  同时还有一些其他的问题,如扫描法,递归的思想, 构造, 分治, 二分等 知识点 单调队列 和 单调栈 题目 UVA - 1606 Am ...

  5. 最大全1子矩阵的两种解法(例题:City Game HDU - 1505)

    以前牛客多校遇到过两道,都没做出来,这次来系统性的补习一下. 例题:City Game HDU - 1505 题意:给你一个矩阵,求最大全1子矩阵,最后结果乘以3... 全1矩阵可以参考下图 这个框就 ...

  6. HDOJ ACM 题目

    转载 HDOJ 题目分类(转) 1001 整数求和 水题 1002 C语言实验题--两个数比较 水题 1003 1.2.3.4.5... 简单题 1004 渊子赛马 排序+贪心的方法归并 1005 H ...

  7. HDOJ题目分类大全

    版权声明:本文为博主原创文章,欢迎转载,转载请注明本文链接! https://blog.csdn.net/qq_38238041/article/details/78178043 杭电里面有很多题目, ...

  8. HDOJ 动态规划总结

    DP是难点,供自已以后系统学习. 1.Robberies 连接 :http://acm.hdu.edu.cn/showproblem.php?pid=2955 背包;第一次做的时候把概率当做背包(放大 ...

  9. hdoj杭电问题分类

    杭电上的题虽然多,但是一直苦于找不到问题分类,网页都是英文的,所以平时做题也没怎么看,今天仔细一看,问题分类竟然就在主页....做了那么久的题居然没发现,表示已经狗带..不要笑,不知道有没有像我一样傻 ...

  10. ACM--DFS--最大碉堡数--HDOJ 1045--Fire Net

    HDOJ题目地址:传送门 Fire Net Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Ot ...

最新文章

  1. mysql统计出每个姓氏的人数_你见过什么偏僻的姓氏?明明是老虎的虎姓氏却读māo...
  2. [ 搭建Redis本地服务器实践系列三 ] :图解Redis客户端工具连接Redis服务器
  3. 《高性能网站建设指南》笔记-2 规则1——减少HTTP请求
  4. ProE二次开发之VS2005+ProE Wildfire 4.0开发环境配置
  5. goland 实用键
  6. python3文件的编码类型是什么_Python3编码类型有哪些?怎么转换?
  7. Spring Boot:(二)启动原理解析
  8. php做乘法表,用PHP生成表单和乘法表
  9. 变量案例弹出用户名(JS)
  10. tsinsen A1333
  11. Shiro自定义Token
  12. 【气体扩散】基于改进的遗传算法求解高斯烟羽模型模拟气体扩散含Matlab代码
  13. iOS安装包ipa文件安装及模拟app版本更新
  14. 中国历史各王朝的知识点总结记忆
  15. 全智通A+常见问题汇总解答—A+维修管理—维修领料,修改领料单材料归属到了另一个维修单下
  16. Android TextView 字体 加粗以及判断是否加粗
  17. 教你找回直接打开outlook附件文件编辑后保存但未另存为的附件文件?
  18. 【Eclipse使用技巧】格式化代码的方法 + 解决注释是繁体字的方法
  19. 牛根生的“牛“,牛在哪里?
  20. 皮革行业分销渠道管理系统有效缩短供销链,提升渠道运营收益

热门文章

  1. 多精度数带余除法_算法笔记 (一) 高精度
  2. 自动驾驶 10-2: 惯性测量单元 (IMU)The Inertial Measurement Unit (IMU)
  3. B-S期权定价模型 Black Scholdz
  4. 596. 超过5名学生的课
  5. 282.给表达式添加运算符
  6. 一元线性回归原理及python简单实现
  7. 用python写WordCount的MapReduce代码
  8. 华为堡垒机_案例:任正非曾为小灵通痛苦8到10年,促进了华为终端公司诞生
  9. python 日志框架_按日期打印Python的Tornado框架中的日志的方法
  10. 使用boost::filesystem实现目录遍历