CodeForces 22B Bargaining Table 简单DP
题目很好理解,问你的是在所给的图中周长最长的矩形是多长
嗯用坐标(x1, y1, x2, y2)表示一个矩形,暴力图中所有矩形
易得递推式:(x1, y1, x2, y2)为矩形的充要条件为:
- (x1, y1, x2, y2) 和 (x1, y1, x2, y2)为合法矩形,即全部为0
- Point(x2, y2) 为 0
当然对X1 == X2这种特殊情况需要特殊判断一下。
Source Code:
//#pragma comment(linker, "/STACK:16777216") //for c++ Compiler
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>
#include <stack>
#include <string>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <vector>
#include <algorithm>
#define Max (a,b) (((a) > (b)) ? (a) : (b))
#define Min (a,b) (((a) < (b)) ? (a) : (b))
#define Abs (x) (((x) > 0) ? (x) : (-(x)))
#define MOD 1000000007
#define pi acos(-1.0) using namespace std; typedef long long ll ;
typedef unsigned long long ull ;
typedef unsigned int uint ;
typedef unsigned char uchar ; template <class T> inline void checkmin (T &a,T b) { if (a > b) a = b; }
template <class T> inline void checkmax (T &a,T b) { if (a < b) a = b; } const double eps = 1e- ;
const int N = ;
const int M = ;
const ll P = 10000000097ll ;
const int INF = 0x3f3f3f3f ; char a[][];
bool cc[][][][];
int n, m; bool check(int x1, int y1, int x2, int y2){
if(x1 >= && x1 <= n){
if(x2 >= x1 && x2 <= n){
if(y1 >= && y1 <= m){
if(y2 >= y1 && y2 <= m){
return true;
}
}
}
}
return false;
} int main(){
int i, j, k, t, numCase = ;
while(cin >> n >> m){
memset(cc, , sizeof(cc));
for(i = ; i <= n; ++i){
for(j = ; j <= m; ++j){
cin >> a[i][j];
}
}
int ans = ;
for(int x1 = ; x1 <= n; ++x1){
for(int x2 = x1; x2 <= n; ++x2){
for(int y1 = ; y1 <= m; ++y1){
for(int y2 = y1; y2 <= m; ++y2){
if((x2 == x1 || check(x1, y1, x2 - , y2)) && (y2 == y1 || check(x1, y1, x2, y2 - )) && a[x2][y2] == ''){
if((x2 == x1 || cc[x1][y1][x2 - ][y2]) && (y1 == y2 || cc[x1][y1][x2][y2 - ])){
cc[x1][y1][x2][y2] = true;
checkmax(ans, * (x2 - x1 + + y2 - y1 + ));
}
} }
}
}
}
cout << ans << endl;
} return ;
}
CodeForces 22B Bargaining Table 简单DP的更多相关文章
- Codeforces 22B Bargaining Table
http://www.codeforces.com/problemset/problem/22/B 题意:求出n*m的方格图中全是0的矩阵的最大周长 思路:枚举 #include<cstdio& ...
- Code Forces 22B Bargaining Table
B. Bargaining Table time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces 1108D - Diverse Garland - [简单DP]
题目链接:http://codeforces.com/problemset/problem/1108/D time limit per test 1 secondmemory limit per te ...
- Codeforces - 702A - Maximum Increase - 简单dp
DP的学习计划,刷 https://codeforces.com/problemset?order=BY_RATING_ASC&tags=dp 遇到了这道题 https://codeforce ...
- Codeforces - 1081C - Colorful Bricks - 简单dp - 组合数学
https://codeforces.com/problemset/problem/1081/C 这道题是不会的,我只会考虑 $k=0$ 和 $k=1$ 的情况. $k=0$ 就是全部同色, $k=1 ...
- Codeforces - 474D - Flowers - 构造 - 简单dp
https://codeforces.com/problemset/problem/474/D 这道题挺好的,思路是这样. 我们要找一个01串,其中0的段要被划分为若干个连续k的0. 我们设想一个长度 ...
- Codeforces - 909C - Python Indentation - 简单dp
http://codeforces.com/problemset/problem/909/C 好像以前做过,但是当时没做出来,看了题解也不太懂. 一开始以为只有上面的for有了循环体,这里的state ...
- CodeForces 30C Shooting Gallery 简单dp
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/qq574857122/article/details/36944227 题目链接:点击打开链接 给定 ...
- Codeforces - 1033C - Permutation Game - 简单dp - 简单数论
https://codeforces.com/problemset/problem/1033/C 一开始觉得自己的答案会TLE,但是吸取徐州赛区的经验去莽了一发. 其实因为下面这个公式是 $O(nlo ...
随机推荐
- zoj 3195 Design the city lca倍增
题目链接 给一棵树, m个询问, 每个询问给出3个点, 求这三个点之间的最短距离. 其实就是两两之间的最短距离加起来除2. 倍增的lca模板 #include <iostream> #in ...
- monkeyrunner学习--手机按键
按下HOME键 device.press('KEYCODE_HOME','DOWN_AND_UP') 按下BACK键 device.press('KEYCODE_BACK','DOWN_AND_UP' ...
- cocos2dx ResolutionPolicy
FrameSize 参数,在游戏运行时,我们可以通过 CCEGLView::sharedOpenGLView()->getFrameSize();如果在手机上运行,那么不同分辨率将会得到不同的值 ...
- DevExpress ASP.NET 使用经验谈(9)-Dev控件客户端事件 ClientSideEvents
上一节,已经介绍了ASPxGridView的自定义列和基本事件 ,本节接着将介绍Dev控件的客户端事件模型. 在上节示例基础上,我们增加一行菜单,使用Dev的ASPxMenu来实现,如下图所示. 图一 ...
- 把Web Form项目转换成MVC项目
http://umbraco.com/follow-us/blog-archive/2013/7/14/moving-from-webforms-to-mvc.aspx https://codinga ...
- js 字符串为空
content.replace(/(^\s)|(\s$)/g, "")
- CentOS-6.3安装配置JDK-7或 JDK-6
链接地址:http://blog.csdn.net/shuixin536/article/details/8954000 http://www.cnblogs.com/zhoulf/archive/2 ...
- java代码获取ip地址
public class IpTool { public static void main(String[] args) { IpTool ipTool=new IpTool(); System.ou ...
- NetBeans文件被锁,无法修改
今天用NetBeans写有关Dojo的一个样例时,出现文件被锁,无法修改的情况.找了半天,但是就是不知道是什么原因,我就写在博客上记录下来
- CURL采集
<?php $url='';//输入'网址 $ch = curl_init(); $timeout = 5;//超时时间 curl_setopt ($ch, CURLOPT_URL, $url) ...