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 ...
随机推荐
- Linux中fork()函数详解(转载)
[原创地址]http://blog.csdn.net/jason314/article/details/5640969 [转载地址]http://www.cnblogs.com/bastard/arc ...
- nodejs的npm安装模块时候报错:npm ERR! Error: CERT_NOT_YET_VALID的解决方法 - 包子博客 _ 关注互联网前端、开发、SEO、移动互联网应用技术
转载:包子博客: http://www.haodewap.net/visit.do?wapurl=http%3A%2F%2Fwww.jincon.com%2Farchives%2F141%2F
- android中使用setVideoURI()播放视频
最近在做一个demo,要求播放视频,记录一下.使用的是VideoView控件,如果播放网络视频的话,视频应该是渐进流式的,格式嘛,大家应该都知道,一般是H.263或者H.264格式的扩展名为3gp或者 ...
- 目前网络上大部分的网站都是由ASP或PHP开发,并且java平台的软件购买成本不适合中小企业客户,一般适用于银行、国家安全等行业领域
目前网络上大部分的网站都是由ASP或PHP开发,并且java平台的软件购买成本不适合中小企业客户,一般适用于银行.国家安全等行业领域. 要求建设开发大型复杂的网站,但仅有一个idea,不能够提供网站详 ...
- Ghost.py 0.1b3 : Python Package Index
Ghost.py 0.1b3 : Python Package Index Ghost.py 0.1b3 Download Ghost.py-0.1b3.tar.gz Webkit based web ...
- swift3.0 hello swift(1)
一直对swift感兴趣,在前段时间的新闻中,大多是swift3.0发布和xcode8.0的改进,因为改动比较大,以前使用swift2.x做项目的人,都在担心其项目从2.x迁移到3.0+的问题.以前简单 ...
- csv批量导入mysql命令
今天把从Kaggle上下载下来的csv数据导入mysql,想做个统计分析,怎奈csv文件有些大.所以仅仅能用mysql 命令导入,现mark下,以备以后不时之需: 1. 导入: 基本的语法: load ...
- uestc 250 数位dp(水)
/* 数位dp 水题 开两维一个记录长度,一个记录上一个数 */ #include<stdio.h> #include<string.h> #define N 13 int d ...
- poj2342 Anniversary party【树形dp】
转载请注明出处,谢谢:http://www.cnblogs.com/KirisameMarisa/p/4316097.html ---by 墨染之樱花 [题目链接]http://poj.org/p ...
- 引用类型List<T>的比较
一:重新Equals和GetHashCode方法 /// <summary> /// 描 述:弹出模型对象列表比较器(根据ID比较) /// </summary&g ...