首页 > 其他分享 >Codeforces Beta Round #22 (Div. 2 Only)-B. Bargaining Table

Codeforces Beta Round #22 (Div. 2 Only)-B. Bargaining Table

时间:2023-06-12 17:34:24浏览次数:45  
标签:office 22 h2 h1 Bargaining int Only dp room


原题链接


B. Bargaining Table



time limit per test



memory limit per test



input



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



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



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






用dp[i][j]表示左上角为(1, 1)右下角为(i,j)的矩形里有多少个1, dp[i][j] = dp[i-1][j] + dp[i][j-1] + dp[i-1][j-1];如果(i,j)本身是1则dp[i][j]++;

遍历每个点(i,j)如果str[i][j] == '0'则把(i,j)表示矩阵的右下角枚举矩阵的左下角(i, h1)和右上角(h2, j)首先判断这个矩阵内1的数目 = dp[i][j] - dp[i][h1-1] - dp[h2-1][j] + dp[h2-1][h1-1], 如果矩阵内没有1则可算矩阵的周长


#include <bits/stdc++.h>
#define maxn 200005
using namespace std;
typedef long long ll;

char str[30][30];
int dp[30][30];
int main(){
	
//	freopen("in.txt", "r", stdin);
	int n, m;
    
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; i++)
     scanf("%s", str[i]+1);
    for(int i = 1; i <= n; i++)
     for(int j = 1; j <= m; j++){
     	if(str[i][j] == '1')
     	 dp[i][j] = 1;
     	dp[i][j] += dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1];
	 }
	int ans = 0;
	for(int i = 1; i <= n; i++)
	 for(int j = 1; j <= m; j++){
	 	    if(str[i][j] == '1')
	 	     continue;
	 		for(int h1 = i-1; h1 >= 0; h1--){
	 		 for(int h2 = j-1; h2 >= 0; h2--){
	 			int d = dp[i][j] - dp[h1][j] - dp[i][h2] + dp[h1][h2];
			    if(d == 0){
			    	ans = max(ans, 2 * (i - h1 + j - h2));
				}
				if(str[i][h2] == '1')
				 break;
			}
			if(str[h1][j] == '1')
				 break;
		   }
	 }
	 printf("%d\n", ans);
	 
	 return 0;
}





标签:office,22,h2,h1,Bargaining,int,Only,dp,room
From: https://blog.51cto.com/u_16158872/6464273

相关文章

  • Codeforces Beta Round #22 (Div. 2 Only)-C. System Administrator
    原题链接C.SystemAdministratortimelimitpertestmemorylimitpertestinputoutputBobgotajobasasystemadministratorinXcorporation.Hisfirsttaskwastoconnec......
  • Codeforces Beta Round #22 (Div. 2 Only)-D. Segments
    原题链接D.SegmentstimelimitpertestmemorylimitpertestinputoutputYouaregiven nInputThefirstlineoftheinputcontainssingleintegernumber n (1 ≤ n ......
  • 关于VS2022使用EF生成实体模型报错的问题:运行转换:System.NullReferenceException:对象
    起因:之前版本vs2022生成EF模型一直没有问题,在更新了最新的vs2022之后,版本号17.6+,出现此问题:运行转换:System.NullReferenceException:对象引用未设置为对象的示例。在Microsoft.VisualStudio.TextTemplatingD21DB4521EFD493FAE41A9CE9DA80C875F3084552987498BD518713BDE91D14A......
  • LightOJ 1422 Halloween Costumes (区间DP)
    题意:你要连续去很多个舞会,给出n个舞会你需要穿的衣服的编号,一旦脱下就不能再穿,但是可以一件套一件,问最少需要准备多少件衣服。思路:区间DP,令dp[i][j]为第i到第j天需要的衣服,那么对于第i天,如果考虑后面没有和它重复的话,那么dp[i][j]=dp[i+1][j]+1,如果存在某一天a[i]==a[k],dp[i][j]=......
  • SM2259XT2开卡长江TAS,附SM2259XT2开卡工具,我更喜欢MAS1102量产工具
    闲的没事干,测一下59xt2+TAS,用的公版主控板,跳线按官方的来,电压给1v2,vcc不用管默认,都能用。随便焊一下,ce齐全,单颗2ce128G,单帖分布2ch/1ce。跑个rdt看看,DDR800。开卡工具是从量产部落下载的YMTC_TAS开卡工具。RDTMaxECC均在十几二十,全新自封片,还算不错体质。直接开卡,轻松开出来,容量aut......
  • 工业互联网2022年工作计划
    ......
  • 喜报|Only&Home新时尚数码家电品牌入驻北京南站,开启消费新风尚
    来源:北京日报网北京南站,做为中国首座高标准现代化的大型综合交通枢纽。位于中国北京市丰台区,是中国铁路北京局集团有限公司管辖的特等站,是北京的第二大火车站,也是北京面积最大、接发车次最多的火车站。2023年6月,Only&Home做为新时尚数码家电品牌,系列产品正式应邀入驻北京南站VIP候......
  • 论文解读 | IROS 2022:基于三维激光雷达的语义位置识别和姿态估计
    原创|文BFT机器人01研究背景这篇论文的背景是在自动驾驶和机器人导航等领域,需要实现高精度、高效率的定位和地点识别。然而,传统的基于GPS或视觉的方法存在一些局限性,尤其在城市峡谷等环境中无法提供准确的位置信息。为了解决这一问题,使用3DLiDAR进行定位和地点识别已经成为一......
  • x01.os.22: 填补一下
    制作LiveCD参考ubuntu官方推荐一键制作在deepin上操作,脚本需要更改为:RELEASE=bionic,makecd.sh代码如下:#!/bin/bash#Author:Redbrother#Email:[email protected]#license:None#data:201910#scriptsin/usr/share/debootstrap/scripts########......
  • English Learning Articles 2022-06-11 Your teen wants to get in shape this summer
    Yourteenwantstogetinshapethissummer?Whattosayandwhentoworry|CNN Ifyourchildrensaytheywanttostartexercisingorworkingoutmorethissummer,don’tcelebratejustyet.Iknowmostparentswouldbethrilledtoseetheirteenstakin......