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. 在ORACLE中如何将一个表中某字段值合计与另一个表的某字段值相减

    现在有两个表,A表字段AMOUNT为发票金额,B表字段REV为收款金额,两表通过字段id关联,需将A表的字段AMOUNT与B表的字段REV相减, 但是A表表示的发票可能对应多个B表的收款金额,如何将A ...

  2. java web 自定义filter

    filter顾名思义,过滤器的意思,在javaweb中的Struts就利用了这种机制去实现视图和业务分离. 这里来配置下自己的Filter来理解下Struts的内在. 在web.xml 中添加下面: ...

  3. oracle存储过程函数

    1.函数 create or replace function get_Destroy_no return varchar2 is Result varchar2(50);begin SELECT m ...

  4. mr中间结果优化

    转载请注明出处:http://blog.csdn.net/lastsweetop/article/details/9187721 作为输入 当压缩文件做为mapreduce的输入时,mapreduce ...

  5. Django 2 创建app

    python manage.py startapp polls 创建model 创建完model以后使用 查看sql python manage.py sql polls 然后使用 python ma ...

  6. Qt下QTableWidget的使用

    1.QTableWidget的基本设置 ui->tableWidget->setColumnCount(11); ui->tableWidget->setRowCount(Nu ...

  7. sqlite笔记(akaedu)

    1.创建sql表create table student(id integer primary key, name text, score integer): 2.插入一条记录insert into ...

  8. 归并排序的C++实现

    原创作品,转载请注明出处:点我 归并排序是建立在归并操作上的一种有效的排序算法,该算法是采用分治法(Divide and Conquer)的一个非常典型的应用.将已有序的子序列合并,得到完全有序的序列 ...

  9. ansible之并行运行

    ansible之并发运行 转载 2016年07月14日 12:33:39 标签: 并发 / ansible 4474 ansible默认只会创建5个进程,所以一次任务只能同时控制5台机器执行.那如果你 ...

  10. wrk -- 小巧轻盈的 http 性能测试工具.

    标签: wrk http 性能 | 发表时间:2015-06-21 00:55 | 作者:zjumty 出处:http://www.iteye.com 测试先行是软件系统质量保证的有效手段. 在单元测 ...