B. Bargaining Table
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters.
Each square meter of the room is either occupied by some furniture, or free. A bargaining table is rectangular, and should be placed so, that its sides are parallel to the office walls. Bob doesn't want to change or rearrange anything, that's why all the squares
that will be occupied by the table should be initially free. Bob wants the new table to sit as many people as possible, thus its perimeter should be maximal. Help Bob find out the maximum possible perimeter of a bargaining table for his office.

Input

The first line contains 2 space-separated numbers n and m (1 ≤ n, m ≤ 25)
— the office room dimensions. Then there follow n lines withm characters
0 or 1 each. 0 stands for a free square meter of the office room. 1 stands for an occupied square meter. It's guaranteed that at least one square meter in the room is free.

Output

Output one number — the maximum possible perimeter of a bargaining table for Bob's office room.

Examples
input
3 3
000
010
000
output
8
input
5 4
1100
0000
0000
0000
0000
output
16
暴力
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h> using namespace std;
int n,m;
char a[30][30];
int main()
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%s",a[i]+1); bool tag=true;
int ans=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(a[i][j]=='1')
continue;
//cout<<a[i][j]<<endl;
for(int l=1;l+i-1<=n;l++)
{
for(int r=1;r+j-1<=m;r++)
{
tag=true;
for(int k=i;k<=i+l-1;k++)
{
for(int p=j;p<=r+j-1;p++)
{
if(a[k][p]=='1')
{
tag=false;break;
}
}
if(!tag)
break;
} if(tag)
ans=max(ans,(l+r)*2);
} }
}
}
printf("%d\n",ans);
return 0; }

Code Forces 22B Bargaining Table的更多相关文章

  1. CodeForces 22B Bargaining Table 简单DP

    题目很好理解,问你的是在所给的图中周长最长的矩形是多长嗯用坐标(x1, y1, x2, y2)表示一个矩形,暴力图中所有矩形易得递推式:(x1, y1, x2, y2)为矩形的充要条件为: (x1, ...

  2. Code Forces 650 C Table Compression(并查集)

    C. Table Compression time limit per test4 seconds memory limit per test256 megabytes inputstandard i ...

  3. CF 22B. Bargaining Table

    水题.好久没有写过优化搜索题了. #include <cstdio> #include <cstring> #include <iostream> #include ...

  4. Codeforces 22B Bargaining Table

    http://www.codeforces.com/problemset/problem/22/B 题意:求出n*m的方格图中全是0的矩阵的最大周长 思路:枚举 #include<cstdio& ...

  5. Bargaining Table

    Bargaining Table time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  6. 思维题--code forces round# 551 div.2

    思维题--code forces round# 551 div.2 题目 D. Serval and Rooted Tree time limit per test 2 seconds memory ...

  7. Inheritance with EF Code First: Part 3 – Table per Concrete Type (TPC)

    Inheritance with EF Code First: Part 3 – Table per Concrete Type (TPC) This is the third (and last) ...

  8. Inheritance with EF Code First: Part 1 – Table per Hierarchy (TPH)

    以下三篇文章是Entity Framework Code-First系列中第七回:Entity Framework Code-First(7):Inheritance Strategy 提到的三篇.这 ...

  9. 暴力/DP Codeforces Beta Round #22 (Div. 2 Only) B. Bargaining Table

    题目传送门 /* 题意:求最大矩形(全0)的面积 暴力/dp:每对一个0查看它左下的最大矩形面积,更新ans 注意:是字符串,没用空格,好事多磨,WA了多少次才发现:( 详细解释:http://www ...

随机推荐

  1. 让低版本IE也能正常运行HTML5+CSS3网站的3种解决方案

    现在我们可以选择浏览器非常多,所以浏览器的环境也是种类繁多,同一个浏览器也是包含各种不同的版本,不同的版本之间的渲染方法也存在差异,,它们支持的 HTML5.CSS3 特性恐怕也不尽相同.这种情况于是 ...

  2. windows phone 应用提交商店失败总结

    应用完成后,在提交微软商店时,可能因为各种各样的问题导致提交审核失败.以前的审核失败并没有总结,希望今后 把各种提交审核失败的情况总结一下,以减少今后提交认证时浪费时间. 1.商店的屏幕截图上不能包含 ...

  3. Linux strace命令使用详解

    strace是Linux环境下的一款程序调试工具,用来监察一个应用程序所使用的系统调用及它所接收的系统信息. 可谓是 linux 下的调试利器,不仅可以用来找程序错误,系统为什么挂死了,命令为什么报错 ...

  4. 禁止Chrome浏览器自动升级

    对于我们测试人员来说,浏览器自动升级是非常可怕的,浏览器的升级会导致出现各种bug,比如我们常用的Selenium,如果Chrome浏览器自动升级就会导致脚本出错,无法打开浏览器等等情况,对于这种情况 ...

  5. spoj687(后缀数组)

    http://www.spoj.com/problems/REPEATS/ 题意:给一串字符,需要你求这一串字符中有连续重复的字符的重复次数....... 思路:这是和poj3693一种类型的题目.. ...

  6. R ggplot2 改变颜色

    p<-ggplot(iris,aes(Petal.Length,Petal.Width,color=Species))+geom_point()cols=c("red",&q ...

  7. [shell]简单的shell提示和参数脚本

    该shell脚本有如下点: bash or dash case语句的写法 脚本help写法 参数是否为空的写法 算数运算的写法 #! /bin/bash case "$1" in ...

  8. xubuntu14.04下编译pjsip及pjsua2 java

    Run "./configure" without any options to let the script detect the appropriate settings fo ...

  9. PHP多进程编程(一)

    虽然PHP 中,多进程用的比较的少.但是毕竟可能是会用到了.我最近就遇到这样一个问题,用户提交几百个url以后,要读出这个url 中的标题. 当然,你不希望用户等待的太久,10s 钟应该给出个答案.但 ...

  10. CI $_GET

    CI默认过滤了$_GET 需要传递get参数时一般直接 /参数一/参数二 详见手册说明:http://codeigniter.org.cn/user_guide/general/controllers ...