CodeForces 1097G. Vladislav and a Great Legend
作者:互联网
题目简述:给定$n \leq 10^5$个节点的树$T = (V, E)$,令$X \subseteq V$表示一个非空节点集合,定义$f(X)$为包含$X$的最小子树的边数。求
$$ \sum_{\emptyset \neq X \subseteq V} (f(X))^k, $$
其中$k \leq 200$。
解:code
问题转化
我们额外定义$f(\emptyset) = 0$,就不需再单独考虑空集。
利用斯特林数的性质,我们有
$$ x^n = \sum_{k=0}^n k! \begin{Bmatrix} n \\ k \end{Bmatrix} \binom{x}{k}. $$
于是,
$$ \sum_{X \subseteq V} (f(X))^k = \sum_{i=0}^k i! \begin{Bmatrix} n \\ k \end{Bmatrix} \sum_{X \subseteq V} \binom{f(X)}{i}. $$
注意到
$$ \sum_{X \subseteq V} \binom{f(X)}{k} = \sum_{X \subseteq V} \sum_{|Y| = k} [Y \subseteq T(X)], $$
其中$T(X)$表示包含$X$的最小子树的边集。
最小子树边集的刻画
我们考虑$X$中所有节点的最近公共祖先是$x$的情况,即$\text{LCA}(X) = x$,则包含$X$的最小子树的边集$T(X)$可被刻画成:若一个节点$u \neq x$,以其为根的子树$T_u$中存在$X$的一个节点,即$T_u \cap X \neq \emptyset$,则$u$与其父节点$\text{pre}(u)$的边$(u, \text{pre}(u))$必定在最小子树中。形式化地,若$\text{LCA}(X) = x$,则
$$ T(X) = \{ (u, \text{pre}(u)): u \in T_x \setminus \{x\} \land X \cap T_u \neq \emptyset \}. $$
广义最小子树边集
在上述讨论中,我们在假设了$\text{LCA}(X) = x$的条件下,得到$T(X)$的刻画。我们现在去掉$\text{LCA}(X) = x$的限制条件,直接对每个节点$x \in V$,定义
$$ F_x(X) = \{ (u, \text{pre}(u)): u \in T_x \setminus \{x\} \land X \cap T_u \neq \emptyset \}. $$
类似地,我们定义
$$ G_x(X) = \{ (u, \text{pre}(u)): u \in T_x \land X \cap T_u \neq \emptyset \}. $$
我们观察到以下两个性质:
观察0:$F_x(\emptyset) = G_x(\emptyset) = \emptyset$。
观察1:若$X \neq \emptyset$,则$G_x(X) = F_x(X) \cup \{ (x, \text{pre}(x)) \}$。
观察2:若$\text{LCA}(X) = x$,则$T(X) = F_x(X)$。
观察3:设$y$是$x$的子节点,即$y \in \text{son}(x)$,则$Y \subseteq G_y(X)$当且仅当$Y \subseteq F_x(X)$且$\text{LCA}(X) \in T_y$。
再次问题转化
我们令$f[x][k]$表示以$x$为根的子树$T_x$中节点的所有子集$X$的广义最小子树$F_x(X)$中选择$k$条边的方案数之和,即
$$ f[x][k] = \sum_{X \subseteq T_x} \sum_{|Y| = k} [Y \subseteq F_x(X)]. $$
令$g[x][k]$表示以$x$为根的子树$T_x$中节点的所有子集$X$最小子树$G_x(X)$中选择$k$条边的方案数之和,即
$$ g[x][k] = \sum_{X \subseteq T_x} \sum_{|Y| = k} [Y \subseteq G_x(X)]. $$
我们枚举$X$的最近公共祖先$\text{LCA}(X)$,则
$$
\begin{aligned}
\sum_{X \subseteq V} \binom{f(X)}{k}
& = \sum_{x \in V} \sum_{X \subseteq V} [\text{LCA}(X) = x] \sum_{|Y| = k} [Y \subseteq T(X)] \\
& = \sum_{x \in V} \sum_{|Y| = k} \sum_{X \subseteq T_x} [\text{LCA}(X) = x \land Y \subseteq T(X)] \\
& = \sum_{x \in V} \sum_{|Y| = k} \sum_{X \subseteq T_x} [\text{LCA}(X) = x \land Y \subseteq F_x(X)] \\
& = \sum_{x \in V} \sum_{|Y| = k} \sum_{X \subseteq T_x} \Big( [Y \subseteq F_x(X)] - [Y \subseteq F_x(X) \land \text{LCA}(X) \neq x] \Big) \\
& = \sum_{x \in V} \sum_{|Y| = k} \sum_{X \subseteq T_x} \left( [Y \subseteq F_x(X)] - \sum_{y \in \text{son}(x)} [Y \subseteq F_x(X) \land \text{LCA}(X) \in T_y] \right) \\
& = \sum_{x \in V} \sum_{|Y| = k} \sum_{X \subseteq T_x} \left( [Y \subseteq F_x(X)] - \sum_{y \in \text{son}(x)} [Y \subseteq G_x(X)] \right) \\
& = \sum_{x \in V} \left( \sum_{|Y| = k} \sum_{X \subseteq T_x} [Y \subseteq F_x(X)] - \sum_{y \in \text{son}(x)} \sum_{|Y| = k} \sum_{X \subseteq T_x} [Y \subseteq G_x(X)] \right) \\
& = \sum_{x \in V} \left( f[x][k] - \sum_{y \in \text{son}(x)} g[y][k] \right) \\
\end{aligned}
$$
动态规划
以上问题转化后,剩下的问题变成了求所有$f[x][k]$和$g[x][k]$。
注意到
$$
\begin{aligned}
g[x][k]
& = \sum_{X \subseteq T_x} \sum_{|Y| = k} [Y \subseteq G_x(X)] \\
& = \sum_{X \subseteq T_x} \sum_{|Y| = k} \Big( [Y \subseteq G_x(X) \land (x, \text{pre}(x)) \in Y] + [Y \subseteq G_x(X) \land (x, \text{pre}(x)) \notin Y] \Big) \\
& = \sum_{X \subseteq T_x} \left( [G_x(X) \neq \emptyset] \sum_{|Y| = k-1} [Y \subseteq F_x(X)] + \sum_{|Y|=k} [Y \subseteq F_x(X)] \right) \\
& = \sum_{X \subseteq T_x} \left( \sum_{|Y| = k-1} [Y \subseteq F_x(X)] + \sum_{|Y|=k} [Y \subseteq F_x(X)] \right) - \sum_{X \subseteq T_x} [G_x = \emptyset] \sum_{|Y| = k-1} [Y \subseteq F_x(X)] \\
& = f[x][k-1]+f[x][k]-[k = 1].
\end{aligned}
$$
设$\text{son}(x) = \{ y_1, y_2, \dots, y_m \}$,则
$$
\begin{aligned}
f[x][k]
& = \sum_{X \subseteq T_x} \sum_{|Y| = k} [Y \subseteq F_x(X)] \\
& = \sum_{X \subseteq T_x} \sum_{|Y| = k} \left( [x \in X \land Y \subseteq F_x(X)] + [x \notin X \land Y \subseteq F_x(X)] \right) \\
& = 2 \sum_{X \subseteq T_x} \sum_{|Y| = k} [x \notin X \land Y \subseteq F_x(X)] \\
& = 2 \sum_{X \subseteq T_x \setminus \{x\}} \sum_{|Y| = k} [Y \subseteq F_x(X)] \\
& = 2 \sum_{X \subseteq T_x \setminus \{x\}} \sum_{X_1 \subseteq T_{y_1}} \cdots \sum_{X_m \subseteq T_{y_m}} \left[ \bigcup_{i=0}^m X_i = X \right] \sum_{|Y| = k} \sum_{Y_1 \subseteq G_{y_1}(X)} \cdots \sum_{Y_m \subseteq G_{y_m}(X)} \left[\bigcup_{i=0}^m Y_i = Y\right] \\
& = 2 \sum_{X_1 \subseteq T_{y_1}} \cdots \sum_{X_m \subseteq T_{y_m}} \sum_{Y_1 \subseteq G_{y_1}(X)} \cdots \sum_{Y_m \subseteq G_{y_m}(X)} \left[\sum_{i=0}^m |Y_i| = k\right] \\
& = 2 \sum_{k_1+k_2+\dots+k_m = k} \left( \sum_{X_1 \subseteq T_{y_1}} \sum_{|Y_1| = k_1} [Y_1 \subseteq G_{y_1}(X)] \right) \cdots \left( \sum_{X_m \subseteq T_{y_m}} \sum_{|Y_m| = k_m} [Y_m \subseteq G_{y_m}(X)] \right) \\
& = 2 \sum_{k_1+k_2+\dots+k_m = k} g[y_1][k_1] \dots g[y_m][k_m]. \\
\end{aligned}
$$
我们可以看到$f[x][k]$的递推式是一个卷积的形式,可以在$O((\min\{\text{size}(x), k\})^2)$的时间复杂度内求解。
总时间复杂度为
$$ \sum_{x \in V} O((\min\{\text{size}(x), k\})^2) = O(kn). $$
标签:Great,right,text,sum,emptyset,LCA,Vladislav,subseteq,Legend 来源: https://www.cnblogs.com/TinyWong/p/10436870.html