https://www.cnblogs.com/RabbitHu/p/51nod1353.htmlhtml
樹形 DP 求全部聯通塊 \(\ge K\) 的方案數.spa
切斷:\(\forall i\in\left[1, s_u\right]\), \(\displaystyle f(u, i) =\sum_{j=1}^{s_v} f(v, j) =f(v, 0)\).code
不切斷:\(\forall i\in\left[1, s_u\right]\), \(\displaystyle \sum_{j=1}^{s_v}f(u, i+j) = f(u, i) f(v, j)\).htm
void dfs(int u, int pre) { dp[u][1]=sz[u]=1; for (int k=head[u], v; k; k=nex[k]) if (v=to[k]!=pre) { dfs(v, u); for (int i=sz[u]; i; --i) { for (int j=1; j<=sz[v]; ++j) dp[u][i+j] = (dp[u][i+j] + dp[u][i]*dp[v][j])%mod; dp[u][i]=dp[u][i]*dp[v][0]%mod; } sz[u]+=sz[v]; } for (int i=K; i<=sz[u]; ++i) dp[u][0]=(dp[u][0]+dp[u][i])%mod; } dfs(1, 0); for (int i=K; i<=sz[i]; ++i) ans=(ans+dp[1][i])%mod;