跳到正文

题解

题解 AT4927 【[AGC033D] Complexity】

小粉兔约 2 分钟
原文
文章信息与版本

文章信息

发布
2020年5月13日
收录
2025年12月12日
更新
2026年11月16日
篇幅
约 2 分钟
获赞
16

版本

  1. v1当前

2019-11-22 补档

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

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

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

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

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

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

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

原文