CodeForces 22B Bargaining Table 简单DP

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

  1. (x1, y1, x2, y2) 和 (x1, y1, x2, y2)为合法矩形,即全部为0
  2. 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 ;
}
上一篇:IntelliJ IDEA 插件开发视频教程


下一篇:Intellij IDEA 插件开发秘籍