QOJ.ac

QOJ

Type: Editorial

Status: Open

Posted by: mierqwq

Posted at: 2026-07-22 16:37:17

Last updated: 2026-07-22 16:37:29

Back to Problem

Editorial for Problem #687

这个数据范围显然是状压 dp。$u$ 排在 $v$ 之前,可视为 $\text{start} \rightarrow u \rightarrow v \rightarrow \text{end}$,即在加入 $v$ 的时刻,$u$ 已经加入。据此,我们定义:

  • $f(S)$ 为:从前往后加点,已加入了集合 $S$ 中的节点,此时的拓扑排序种数。用于处理 $\text{start} \rightarrow v$ 这一段。
  • $g(S)$ 为:从后往前删点,还未删除集合 $S$ 中的节点,此时的拓扑排序种数。用于处理 $v \rightarrow \text{end}$ 这一段。

求 $f,g$ 可做到 $O(2^n \cdot n)$。统计答案时,对于 $(u,v)$,答案即为 $\sum_{u \in S,v\notin S} f(S) \cdot g(S \cup\{v\})$,暴力累加即可,复杂度 $O(2^n \cdot n^2)$,卡一卡能过。

Comments

No comments yet.