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 with m 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.

Sample test(s)
input
3 3
000
010
000
output
8
input
5 4
1100
0000
0000
0000
0000
output
16

这题该怎么说呢,不难,但是又做了挺久。。。

遍历每一个点vi,算出以vi为左上角的谈判桌的最大周长p(vi),取max(p(vi))。有一些简单的剪枝操作,也不值一提。

AC Code:

 #include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std; const int SZ = ;
char map[SZ][SZ];
int n, m; int Solve(int y, int x)
{
int w = , d, maxP = ;
for(int i = y; i < n; i++)
{
int j;
for(j = x; j < m; j++)
{
if(map[i][j] == '') break;
}
if(j != x) d = i - y + ;
else break;
if(w > j - x) w = j - x;
int t = (d + w) << ;
if(t > maxP) maxP = t;
}
return maxP;
} int main()
{
while(scanf("%d %d", &n, &m) != EOF)
{
for(int i = ; i < n; i++)
scanf("%s", map[i]);
int maxP = ;
for(int i = ; i < n; i++)
{
for(int j = ; j < m; j++)
{
if(map[i][j] == '')
{
int t = Solve(i , j);
if(maxP < t) maxP = t;
}
}
}
printf("%d\n", maxP);
}
return ;
}

Bargaining Table的更多相关文章

  1. Code Forces 22B Bargaining Table

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

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

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

  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. CodeForces 22B Bargaining Table 简单DP

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

  6. S8-codelab02

    import news_cnn_model import numpy as np import os import pandas as pd import pickle import shutil i ...

  7. CF dp 题(1500-2000难度)

    前言 从后往前刷 update 新增 \(\text{\color{red}{Mark}}\) 标记功能,有一定难度的题标记为 \(\text{\color{red}{红}}\) 色. 题单 (刷过的 ...

  8. 散列表(hash table)——算法导论(13)

    1. 引言 许多应用都需要动态集合结构,它至少需要支持Insert,search和delete字典操作.散列表(hash table)是实现字典操作的一种有效的数据结构. 2. 直接寻址表 在介绍散列 ...

  9. React使用antd Table生成层级多选组件

    一.需求 用户对不同的应用需要有不同的权限,用户一般和角色关联在一起,新建角色的时候会选择该角色对应的应用,然后对应用分配权限.于是写了一种实现的方式.首先应用是一个二级树,一级表示的是应用分组,二级 ...

随机推荐

  1. 软件工程课堂练习——找出1-n中1出现的个数

    题目:给定一个十进制的正整数,写下从1开始,到N的所有整数,然后数一下其中出现“1”的个数. 要求:写一个函数 f(N) ,返回1 到 N 之间出现的 “1”的个数.例如 f(12)  = 5. 在3 ...

  2. MacOS下安装Requests库及使用

    大概框架 Request库的安装 爬取网页最好用的第三方库 直接安装即可(用于OS X) pip3 install requests request库的常用方法: request库一共有七个常用方法. ...

  3. [ Selenium2 从零开始 by Bruce from http://seleniumcn.cn ] 1-8 视频集锦

    内容转自: http://blog.csdn.net/sxl0727tu/article/details/51887093\ ************************************* ...

  4. android Eclipse there no select

    点mainactivity类 右键  run as 进行 配置 就可运行

  5. vue h render function & render select with options bug

    vue h render function & render select with options bug https://github.com/xgqfrms/vue/issues/41 ...

  6. jquery截取手机号中间4位数,然后变为*

    $(function() { var phone = $('#phone').text(); var mphone = phone.substr(0, 3) + '****' + phone.subs ...

  7. HDU4753 Fishhead’s Little Game——2013 ACM/ICPC Asia Regional Nanjing Online

    今天比赛又是做得好水的.被狂虐啊. 比赛两个多小时一直没出题,遒遒最先交的若干发都wa了.T_T 我独自在一遍苦思了1006这个题,还好最后把这个题目A掉了,不然又是深坑队友. 题目的意思我就不多说了 ...

  8. Object 接受集合里面的任意数据类型 所有的类型默认继承object

  9. bzoj2013[CEOI2010] A huge tower

    题意 有N(2<=N<=620000)快砖,要搭一个N层的塔,要求:如果砖A恰好在砖B上面,那么A不能比B的长度+D要长.问有几种方法,输出 答案 mod 1000000009的值 分析 ...

  10. DjangoORM字段参数介绍

    参数介绍: 字段的参数:     null:             ->db是否可以为空     default:          ->默认值     primary_key:     ...