City Game

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

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
题意:求'F'组成的最大子矩阵
题解:跟hdu1506一样,对每列分别求最大子矩阵。。但是死活WA,不写了。。
补:预处理有问题。。
  1. #include<stdio.h>
  2. #include<iostream>
  3. #include<string.h>
  4. #include<math.h>
  5. #include<algorithm>
  6. using namespace std;
  7. const int N = ;
  8.  
  9. int n,m;
  10. char a[N][N];
  11. int mp[N][N];
  12. int L[N],R[N];
    void input()
    {
        int i,j;
        for(i=1; i<=n; i++)
            for(j=1; j<=m; j++)
                cin>>a[i][j];
        for(i=1; i<=m; i++)
            mp[0][i]=0;
        for(i=1; i<=m; i++)
        {
            for(j=1; j<=n; j++)
            {
                if(a[j][i]=='F')
                    mp[j][i]=mp[j-1][i]+1;
                else
                    mp[j][i]=0;
            }
        }
        /*for(int i=1;i<=n;i++){ //test
            for(int j=1;j<=m;j++){
                printf("%d ",mp[i][j]);
            }
            printf("\n");
        }*/
    }
  13. /*void input(){
  14. memset(mp,0,sizeof(mp));
  15. for(int i=1;i<=n;i++){
  16. gets(a[i]);
  17. for(int j=1;j<=m;j++){
  18. if(i==1) { ///预处理mp
  19. if(a[i][(j-1)*2]=='R') mp[i][j]=0;
  20. if(a[i][(j-1)*2] =='F') mp[i][j]=1;
  21. }else{
  22. if(a[i-1][(j-1)*2]=='R') {
  23. if(a[i][(j-1)*2] =='R') mp[i][j]=0;
  24. if(a[i][(j-1)*2] =='F') mp[i][j]=1;
  25. }
  26. else {
  27. if(a[i][(j-1)*2] =='R') mp[i][j]=0;
  28. if(a[i][(j-1)*2] =='F') mp[i][j]+=mp[i-1][j]+1;
  29. }
  30. }
  31. }
  32. }
  33. /*for(int i=1;i<=n;i++){ //test
  34. for(int j=1;j<=m;j++){
  35. printf("%d ",mp[i][j]);
  36. }
  37. printf("\n");
  38. }*/
  39. }*/
  40. int main()
  41. {
  42. int tcase;
  43. scanf("%d",&tcase);
  44. while(tcase--){
  45. scanf("%d%d",&n,&m);
  46. getchar();
  47. input();
  48. int mx = -;
  49. for(int k=;k<=n;k++){
  50. L[]=;
  51. R[m]=m;
  52. for(int i=;i<=m;i++){ ///向右延伸
  53. int t = i;
  54. if(t>&&mp[k][i]<=mp[k][t-]) t = L[t-];
  55. L[i] =t;
  56. }
  57. for(int i=m-;i>=;i--){
  58. int t = i;
  59. if(t<m&&mp[k][i]<=mp[k][t+]) t = R[t+];
  60. R[i] = t;
  61. }
  62. for(int i=;i<=m;i++){
  63. if((R[i]-L[i]+)*mp[k][i]>mx) mx = (R[i]-L[i]+)*mp[k][i];
  64. }
  65. }
  66. printf("%d\n",mx*);
  67. }
  68.  
  69. }

hdu 1505(最大子矩阵)的更多相关文章

  1. HDU 1505 City Game (hdu1506 dp二维加强版)

    F - City Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi ...

  2. hdu 1505(dp求最大子矩阵)

    题意:就是让你求出全由F组成的最大子矩阵. 分析:这是hdu 1506的加强版,只不过这道题变成了2维的,那我们就一行一行的来.具体的分析见1506的博客:http://www.cnblogs.com ...

  3. POJ 1964&HDU 1505&HOJ 1644 City Game(最大0,1子矩阵和总结)

    最大01子矩阵和,就是一个矩阵的元素不是0就是1,然后求最大的子矩阵,子矩阵里的元素都是相同的. 这个题目,三个oj有不同的要求,hoj的要求是5s,poj是3秒,hdu是1秒.不同的要求就对应不同的 ...

  4. hdu 1559 最大子矩阵

    最大子矩阵 Time Limit: 30000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  5. hdu 1081(最大子矩阵和)

    题目很简单,就是个最大子矩阵和的裸题,看来算法课本的分析后也差不多会做了.利用最大子段和的O(n)算法,对矩阵的行(或列)进行 i和j的枚举,对于第 i到j行,把同一列的元素进行压缩,得到一整行的一维 ...

  6. hdu 1559 最大子矩阵 (简单dp)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1559 #include <cstring> #include <cstdlib> ...

  7. HDU 1559 最大子矩阵 (DP)

    题目地址:pid=1559">HDU 1559 构造二维前缀和矩阵.即矩阵上的点a[i][j]表示左上方的点为(0,0),右下方的点为(i,j)的矩阵的和.然后枚举每一个矩阵的左上方的 ...

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

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

  9. ACM HDU 1559 最大子矩阵

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1559 这道题 挺好的,当时想出解法的时候已经比较迟了.还是平时看得少. 把行与列都进行压缩.ans[i ...

随机推荐

  1. JNA的用法

    JNA(Java Native Access):建立在JNI之上的Java开源框架,SUN主导开发,用来调用C.C++代码,尤其是底层库文件(windows中叫dll文件,linux下是so[shar ...

  2. Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) A B C D 水 模拟 构造

    A. Neverending competitions time limit per test 2 seconds memory limit per test 512 megabytes input ...

  3. HDU1540 区间合并

    Tunnel Warfare Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  4. XMind 8 破解补丁 XMindCrack.jar注册机激活教程

    XMind 8 破解补丁 XMindCrack.jar注册机激活教程 Xmind 8 update7破解版(附破解教程|激活补丁|序列号) 思维导图 XMind 8 Update 7 Pro 破解版 ...

  5. [LeetCode] Binary Tree Level Order Traversal 与 Binary Tree Zigzag Level Order Traversal,两种按层次遍历树的方式,分别两个队列,两个栈实现

    Binary Tree Level Order Traversal Given a binary tree, return the level order traversal of its nodes ...

  6. HEOI 2012 旅行问题

    2746: [HEOI2012]旅行问题 Time Limit: 30 Sec  Memory Limit: 256 MBSubmit: 1009  Solved: 318[Submit][Statu ...

  7. [Luogu 3958] NOIP2017 D2T1 奶酪

    题目链接 人生第一篇题解,多多关照吧. 注意事项: 1.多组数据,每次要先初始化. 2.因为涉及到开根,所以记得开double. 整体思路: 建图,判断「起点」与「终点」是否连通. 方法可选择搜索(我 ...

  8. 使用python脚本配置zabbix发送报警邮件

    #前提得在zabbix_server配置文件中配置触发脚本的目录,例如,我配置的在/usr/local/zabbix/server/scripts目录下 编写python脚本如下 因为我的服务器在腾讯 ...

  9. 32岁白发菜鸟拿2.6万年薪苦熬10年 NBA首秀便惊艳世人 科比书豪纷纷为他点赞

    这是一场普通的常规赛——斯台普斯球馆,湖人的赛季第81场.比赛的结果也没什么意外:客场作战的火箭106-99带走胜利.然而,这一场的斯台普斯却成了欢乐的海洋,现场甚至喊出了MVP的呼声,这份赞誉,送给 ...

  10. Vue 使用中的小技巧(山东数漫江湖)

    在vue的使用过程中会遇到各种场景,当普通使用时觉得没什么,但是或许优化一下可以更高效更优美的进行开发.下面有一些我在日常开发的时候用到的小技巧,在下将不定期更新~ 1. 多图表resize事件去中心 ...