题目大意:
求出平面上n个点组成的一个包含顶点数最多的凸多边形。n<=250.
Sol:
首先考虑O(n^4)算法。
将所有点按照水平序排序。
首先枚举最左侧的点,考虑在这种情况下down[i][j](表示最右侧的两个点为i,j)下凸壳上的最大点数。
与之同理,枚举最右侧的点,考虑此时up[i][j](表示最左侧的点i,j)上凸壳上的最大点数。
此时状态O(n^2),转移O(n),n次dp,总复杂度为O(n^4).
对于答案,我们只需枚举左右两个端点,O(n)合并dp最优值即可。总复杂度为O(n^3).
因此,总的时间复杂度为O(n^4).
代码如下:
#include <cstdio>
#include <cstring>
#include <cctype>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 251
struct Point {
int x, y;
Point(int _x = 0, int _y = 0):x(_x),y(_y){}
bool operator < (const Point &B) const {
return x < B.x || (x == B.x && y < B.y);
}
Point operator - (const Point &B) const {
return Point(B.x - x, B.y - y);
}
void read() {
scanf("%d%d", &x, &y);