题解 AT4927 【[AGC033D] Complexity】

· · 题解

2019-11-22 补档

考虑一个朴素的 DP:dp(\mathit{topleft}, \mathit{bottomright}) 表示左上角为 \mathit{topleft},右下角为 \mathit{bottomright} 时这个矩形区域的权值。

状态数就是 \mathcal O (H^2 W^2) 的了,考虑优化状态。

容易发现权值最大不超过 \lceil \log_2 H \rceil + \lceil \log_2 W \rceil,且在当 (i + j) \bmod 2 = 0 时 A_{ij} 为.否则为#,即黑白染色时取到上限。

那么记 f(\mathit{complexity}, \mathit{top}, \mathit{bottom}, \mathit{left}) 为满足 dp(\mathit{topleft}, \mathit{bottomright}) \le \mathit{complexity} 的最大的 \mathit{right} 值,如果不存在这样的 \mathit{right} 则为 \mathit{left} - 1。

同理记 g(\mathit{complexity}, \mathit{left}, \mathit{right}, \mathit{top}) 为满足 dp(\mathit{topleft}, b\mathit{ottomright}) \le \mathit{complexity} 的最大的 \mathit{bottom} 值,如果不存在这样的 \mathit{bottom} 则为 \mathit{top} - 1。

这样子就可以实现转移,具体方式是:以 \mathit{complexity} 为阶段,每次从上一个阶段转移而来(可以滚动数组)。
先考虑 f 只算劈成左右两半的方案的贡献,g 只算劈成上下两半的方案的贡献,这样子可以直接以 f(\mathit{top}, \mathit{bottom}, \mathit{left}) = f'(\mathit{top}, \mathit{bottom}, f'(\mathit{top}, \mathit{bottom}, \mathit{left}) + 1) 的方式进行转移。g 同理,最后再固定 \mathit{topleft},利用双指针进行合并即可。

时间复杂度为 \mathcal O (W H (W + H) \log WH),评测链接。