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
  1. 3 3
  2. 000
  3. 010
  4. 000
output
  1. 8
input
  1. 5 4
  2. 1100
  3. 0000
  4. 0000
  5. 0000
  6. 0000
output
  1. 16
  1. 暴力
  1. #include <iostream>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <algorithm>
  5. #include <math.h>
  6. #include <stdio.h>
  7. using namespace std;
  8. int n,m;
  9. char a[30][30];
  10. int main()
  11. {
  12.     scanf("%d%d",&n,&m);
  13.     for(int i=1;i<=n;i++)
  14.         scanf("%s",a[i]+1);
  15.     bool tag=true;
  16.     int ans=0;
  17.     for(int i=1;i<=n;i++)
  18.     {
  19.         for(int j=1;j<=m;j++)
  20.         {
  21.             if(a[i][j]=='1')
  22.                 continue;
  23.             //cout<<a[i][j]<<endl;
  24.             for(int l=1;l+i-1<=n;l++)
  25.             {
  26.                 for(int r=1;r+j-1<=m;r++)
  27.                 {
  28.                     tag=true;
  29.                     for(int k=i;k<=i+l-1;k++)
  30.                     {
  31.                         for(int p=j;p<=r+j-1;p++)
  32.                         {
  33.                             if(a[k][p]=='1')
  34.                                {
  35.                                    tag=false;break;
  36.                                }
  37.                         }
  38.                         if(!tag)
  39.                             break;
  40.                     }
  41.                     if(tag)
  42.                        ans=max(ans,(l+r)*2);
  43.                 }
  44.             }
  45.         }
  46.     }
  47.     printf("%d\n",ans);
  48.     return 0;
  49. }
  50.  

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. PHPStorm 10 激活

    按照这篇东东的说法去做已经不行了~ 可以参考我的另外一篇~ 传送门: http://www.cnblogs.com/gssl/p/5686612.html 楼主的图片看不到,下面是我找到的.分享出来. ...

  2. 使用Cookie报错Control character in cookie value, consider BASE64 encoding your value

    参考资料: http://www.blogjava.net/persister/archive/2009/10/02/297103.html http://blog.csdn.net/xiaozhen ...

  3. java的map取值

    第一种方法根据键值的名字取值 import java.util.HashMap; import java.util.Map; /**   * @param args   */  public stat ...

  4. C语言 · 最大乘积

      算法提高 最大乘积   时间限制:1.0s   内存限制:512.0MB      问题描述 对于n个数,从中取出m个数,如何取使得这m个数的乘积最大呢? 输入格式 第一行一个数表示数据组数 每组 ...

  5. [Linux]Linux printf 输出重定向

    方法一 #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <sys/st ...

  6. 1.apache php mysql phpmyadmin的安装配置

    一.安装apache ①.双击文件Apach_2.2.8_win32-x86-no_ssl.msi,弹出欢迎界面.单NEXT按钮,进入到License Agreement(许可协议)界面. 同意并ne ...

  7. P2P网络穿越 NAT穿越

    http://blog.csdn.net/mazidao2008/article/details/4933730 ——————————————————————————————————————————— ...

  8. SQL之Join的使用

    一.基本概念 关于sql语句中的连接(join)关键字,是较为常用而又不太容易理解的关键字,下面这个例子给出了一个简单的解释 –建表user1,user2: table1 : create table ...

  9. MyBatis应用程序根据XML配置文件创建SqlSessionFactory

    MyBatis应用程序根据XML配置文件创建SqlSessionFactory,SqlSessionFactory在根据配置,配置来源于两个地方,一处是配置文件,一处是Java代码的注解,获取一个Sq ...

  10. php -- PDO事务处理

    事务处理流程 开启事务 PDO::beginTransaction 事务操作 所有的实务操作就是增删改 事务提交 PDO::commit:成功后提交数据 PDO::rollback:失败后回滚数据 & ...