HDU1505

City Game

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

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

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<cstdlib>
 6 using namespace std;
 7 #define maxn 1000+5
 8 int dp[maxn][maxn];
 9 int l[maxn],r[maxn];
10 int main()
11 {
12     int n,m,ans;
13     char c[10];
14     int t;
15     scanf("%d",&t);
16     while(t--)
17     {
18         scanf("%d%d",&n,&m);
19         memset(dp,0,sizeof(dp));
20         for(int i=1;i<=n;i++)
21         {
22             for(int j=1;j<=m;j++)
23             {
24                 scanf("%s",&c);
25                 if(c[0]==‘F‘)
26                     dp[i][j]=dp[i-1][j]+1;
27                 else
28                     dp[i][j]=0;
29             }
30         }
31
32             int ans=0;
33             for(int i=1;i<=n;i++)
34             {
35                 l[1]=1;
36                 r[m]=m;
37                 dp[i][0]=-1;
38                 dp[i][m+1]=-1;
39                 for(int j=2;j<=m;j++)
40                 {
41                     l[j]=j;
42                     while(dp[i][l[j]]<=dp[i][l[j]-1])
43                         l[j]=l[j]-1;
44                 }
45                 for(int j=m-1;j>=1;j--)
46                 {
47                     r[j]=j;
48                     while(dp[i][r[j]]<=dp[i][r[j]+1])
49                         r[j]=r[j]+1;
50                 }
51                 for(int j=1;j<=m;j++)
52                     ans=max(ans,(r[j]-l[j]+1)*dp[i][j]);
53             }
54         printf("%d\n",ans*3);
55     }
56     return 0;
57 }
时间: 2024-08-27 03:48:34

HDU1505的相关文章

HDU1505(HDU1506的加强版)

昨天打 CF又跪了,最近睡不好睡不好睡不好-感觉整个人都累傻了,根本无办法写下去,仅仅写了一题签到题就跪了orz..从未试过这么悲剧. 今天早上凭着我的意念("怨念"),七点又起来了!我已经连续好多天七点自动起来(不是自然醒,是意念,是意念....),刷啊刷啊刷dp. 今天刷的是昨天的加强版,实际上就多了一个for循环,和做高度处理,不直到是不是正解(  ╮(╯▽╰)╭ ),但是AC就好了... 经过多次调试我的shell脚本,这个acm.sh算是比较稳定了,还差一个自动提交机啊!我的

HDU 1506 &amp;&amp; HDU1505 &amp;&amp; HDU 2870 (DP).

~~~~ 这三道DP题是逐层递进的,大家可以从前往后做. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1506 http://acm.hdu.edu.cn/showproblem.php?pid=1505 http://acm.hdu.edu.cn/showproblem.php?pid=2870 ~~~~ 1506: 分别找每一块板子的可以的最左边界和最右边界,注意这时不能用两个for暴力(显然会TLE),所以要用DP的思想边搜边保存. 另外注

hdu1505 dp

1 //Accepted 5196 KB 109 ms 2 //类似hdu1506 3 //输入数据的格式没有明确的限制 4 //可能出现以下情况 5 //5 5 6 //R 7 //F 8 //F F F 9 //F F F F F 10 //R R R 11 //R R 12 //R F R F R 13 //R R R R R 14 #include <cstdio> 15 #include <cstring> 16 #include <iostream> 17

hdu1505(dp求最大子矩阵)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1505 分析: 这题是HDU 1506 的加强版,定义一个二维数组,d[i][j]表示第i行j列元素在前i行中的最大高度.(以第一行为底)例如测试样例: 0 1 1 1 1 1                                                 0 1 1 1 1 1 1 1 1 1 1 1           (F=1,R=0,方便求和)        1 2 2 2 2

hdu 2830 Matrix Swapping II(hdu1505的加强版)

#include<cstdio> #include<cstring> #include<algorithm> #define N 1005 using namespace std; const int INF=1<<30; char mat[N][N]; int a[N][N]; int L[N],R[N]; int main() { int m,n; memset(a,0,sizeof(0)); while(scanf("%d%d",&

DP总结 ——QPH

常见优化 单调队列 形式 dp[i]=min{f(k)} dp[i]=max{f(k)} 要求 f(k)是关于k的函数 k的范围和i有关 转移方法 维护一个单调递增(减)的队列,可以在两头弹出元素,一头压入元素. 队列中维护的是两个值.一个是位置,这和k的范围有关系,另外一个是f(k)的值,这个用来维护单调性,当然如果f(k)的值可以利用dp值在O(1)的时间内计算出来的话队列中可以只维护一个表示位置的变量. 枚举到一个i的时候,首先判断队首元素的位置是否已经不满足k的范围了,如果不满足就将队首

HDU动规46 转载

HDU 动态规划(46道题目)倾情奉献~ [只提供思路与状态转移方程] 收藏 Robberies http://acm.hdu.edu.cn/showproblem.php?pid=2955     背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱  最脑残的是把总的概率以为是抢N家银行的概率之和… 把状态转移方程写成了f[j]=max{f[j],f[j-q[i].v]+q[i].money}(f[j]表示在概率j之下能抢的大洋);        正确的

转载:hdu 动态规划题集

1.Robberies 连接 :http://acm.hdu.edu.cn/showproblem.php?pid=2955     背包;第一次做的时候把概率当做背包(放大100000倍化为整数):在此范围内最多能抢多少钱  最脑残的是把总的概率以为是抢N家银行的概率之和… 把状态转移方程写成了f[j]=max{f[j],f[j-q[i].v]+q[i].money}(f[j]表示在概率j之下能抢的大洋);    正确的方程是:f[j]=max(f[j],f[j-q[i].money]*q[i

hdu2870(dp求最大子矩阵)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2870 分析:分别转换成'a','b','c'三种来求,其实就跟hdu1505一样了... #include <cstdio> #include <cstring> #include <cmath> #include <iostream> #include <algorithm> #include <queue> #include <