Solution
关键性质:先手最多只会留下 个点。
证明很简单,如果留下大于 个点,可以把不影响外接矩形大小的点删掉,只剩下小于等于 个。
矩形的周长由两个 坐标和两个 坐标决定,是 。
考虑状压这四个坐标有没有确定,设 为考虑前 个点,当前确定状态为 。 是一个 位二进制数,转移时枚举当前这个点确定了的集合 ,转移:
- 时,。
- 时,。
设 ,如果 是枚举子集,复杂度 。如果是直接枚举,复杂度 。
代码实现的是前者。
Code
const int N = 3e5 + 5, full = 15;
int n, px[N], py[N], c[N], f[2][20];
void sol() {
cin >> n;
F(i, 1, n) cin >> px[i];
F(i, 1, n) cin >> py[i];
F(i, 1, n) cin >> c[i];
int u = 0;
memset(f[u], -0x3f, sizeof f[u]);
f[0][0] = 0;
F(i, 1, n) {
u ^= 1;
memset(f[u], -0x3f, sizeof f[u]);
F(s, 0, full) {
ckmax(f[u][s], f[u^1][s] + c[i]);
for (int t = s; t; t = (t-1)&s) {
int cur = 0;
if (t & 1) cur += px[i] * 2;
if (t >> 1 & 1) cur -= px[i] * 2;
if (t >> 2 & 1) cur += py[i] * 2;
if (t >> 3 & 1) cur -= py[i] * 2;
ckmax(f[u][s], f[u^1][s^t] + cur);
}
}
}
cout << f[u][full] << '\n';
}