Problem(A22):Party

Judge Info
Memory Limit: 32768KB
Case Time Limit: 10000MS
Time Limit: 10000MS
Judger: Number Only Judger

Description
Frog Frank is going to have a party, he needs a large empty rectangular place. He ranted a large rectangular place in the forest, unfortunately the place is not empty, there are some trees in it. For solving the problem, he makes a map of the rectangular place with m × n grid, he paint the grid to black if there are some trees in it. Now, all he needs to do is find the largest rectangular place in the map contains no black grid.

Task
Frank is asking your help to find out, the area(the number of grids) of the largest rectangular place without black grid.

Input
The first line of input contains , the number of test cases. For each test case, the first contains two integer number m and n , denotes the size of the map. In the next m lines, each line contains a string with n ’0’,’1’ characters, ’0’ denotes the empty grid, ’1’ denotes the black grid.

Output
For each test case, print the area(the number of grids) of the largest rectangular place in a line.

Sample Input
2
3 3
111
100
111
5 5
10101
00100
00000
00000
00001
Sample Output
2
12

分析:n,m最大值为10,总时间竟然给了10s!本来还担心时间问题,一看这规模完全不用了.
注:我把本题中01地位互换了一下.
设f[i][j]为第i行第j列左边有多少个连续的1(包括第j列)
对于某个f[i][j]如果f[i-1][j]>f[i][j],那不妨扩充一层,向下类似,直到f[x][j]>f[i][j]为止.这样我们就得到了一个由[i,j]张成的矩形.通过比较这n*m个矩形就可以得出最大面积了.

#include<stdio.h>
#include<string.h>
][];
][];
int main()
{
    int T;
    scanf("%d",&T);
    int n,m;
    while (T--)
    {
        scanf("%d%d",&n,&m);
        memset(f,,sizeof(f));
        int i,j,k;
        ;i<=n;i++) scanf("%s",s[i]);
        ;i<=n;i++)
            ;j<=m;j++)
                ]==;
                ;
        ;i<=n;i++)
            ;j<=m;j++)
                ) f[i][j]=f[i][j-]+;
        int Max=0,l,r;
        ;i<=n;i++)
            ;j<=m;j++)
            {
                ;k--)
                    ][j]<f[i][j])
                    {
                        l=k;
                        break;
                    }
                for (k=i;k<=n;k++)
                    ][j]<f[i][j])
                    {
                        r=k;
                        break;
                    }
                )>Max) Max=f[i][j]*(r-l+);
            }
        printf("%d\n",Max);
    }
    ;
}

SZU-A22的更多相关文章

  1. SZU:B47 Big Integer II

    Judge Info Memory Limit: 32768KB Case Time Limit: 10000MS Time Limit: 10000MS Judger: Normal Descrip ...

  2. SZU:D89 The Settlers of Catan

    Judge Info Memory Limit: 65536KB Case Time Limit: 3000MS Time Limit: 3000MS Judger: Number Only Judg ...

  3. SZU:B47 Big Integer I

    Judge Info Memory Limit: 32768KB Case Time Limit: 10000MS Time Limit: 10000MS Judger: Normal Descrip ...

  4. SZU:G32 Mass fraction

    Judge Info Memory Limit: 32768KB Case Time Limit: 5000MS Time Limit: 5000MS Judger: Float Numbers (1 ...

  5. SZU:J38 Number Base Conversion

    Judge Info Memory Limit: 32768KB Case Time Limit: 1000MS Time Limit: 1000MS Judger: Number Only Judg ...

  6. SZU:B54 Dual Palindromes

    Judge Info Memory Limit: 32768KB Case Time Limit: 10000MS Time Limit: 10000MS Judger: Number Only Ju ...

  7. SZU:A66 Plastic Digits

    Description There is a company that makes plastic digits which are primarily put on the front door o ...

  8. SZU:G34 Love code

    Judge Info Memory Limit: 32768KB Case Time Limit: 10000MS Time Limit: 10000MS Judger: Normal Descrip ...

  9. SZU:A25 Favorite Number

    Judge Info Memory Limit: 32768KB Case Time Limit: 10000MS Time Limit: 10000MS Judger: Number Only Ju ...

  10. SZU:A26 Anagram

    Judge Info Memory Limit: 32768KB Case Time Limit: 10000MS Time Limit: 10000MS Judger: Normal Descrip ...

随机推荐

  1. 算法与数据结构(十七) 基数排序(Swift 3.0版)

    前面几篇博客我们已经陆陆续续的为大家介绍了7种排序方式,今天博客的主题依然与排序算法相关.今天这篇博客就来聊聊基数排序,基数排序算法是不稳定的排序算法,在排序数字较小的情况下,基数排序算法的效率还是比 ...

  2. bzoj 1061 志愿者招募 有上下界费用流做法

    把每一天看作一个点,每一天的志愿者数目就是流量限制,从i到i+1连边,上下界就是(A[i],+inf). 对于每一类志愿者,从T[i]+1到S[i]连边,费用为招募一个志愿者的费用,流量为inf.这样 ...

  3. 20151208Study

    20151208-----------------------------------------------------* Her main interest now is raising her ...

  4. Monkey测试的策略和分析

    Monkey测试针对不同的对象和不同的目的采用不同的测试方案,首先测试的对象.目的及类型如下: 测试的类型分为:应用程序的稳定性测试和压力测试 测试对象分为:单一apk和apk集合 测试的目的分为:解 ...

  5. java之容器

    先来一张容器的API框架图,我们在java中所学的所有知识,都是根据下面这张图来学习的.... 容器API: 1.Collection接口------定义了存储一组对象的方法,其子接口Set和List ...

  6. windows下vagrant使用及工作环境配置

    环境搭建记录(2014-08-01) 操作系统: Win7旗舰版 Vagrant版本: 1.6 搭建过程 安装vagrant 右键打开安装包按照提示安装即可 安装后会自动把vagrant添加到环境变量 ...

  7. UVA1262Password(第K字典序)

    题目链接 紫书P323 题意:两个6*5的字母矩阵,两个矩阵每列相同的字母,每列取一个,求按照字典序第k小的序列 分析: 对于第一个样例来说,我们得到{ACDW}.{BOP}.{GMOX}.{AP}. ...

  8. 加载不同的nib文件

    只需要实现nibName方法即可 另外还需在vc控制器初始化的时候不指定对应的nib文件名 -(NSString *)nibName { if(UI_USER_INTERFACE_IDIOM() == ...

  9. jhat中的OQL(对象查询语言)

    http://blog.csdn.net/wanglha/article/details/40181767 jhat中的OQL(对象查询语言) 如果需要根据某些条件来过滤或查询堆的对象,这是可能的,可 ...

  10. Android 开发环境搭建9传送帖)

    ---恢复内容开始--- 首先,得安装软件,感觉我所找到的一些课本上写的都比较简略,走过一些弯路后,决定按照这个百度经验来 Android安卓开发环境搭建详细教程 http://jingyan.bai ...