感觉 AT 和 CF 甚至模拟赛都很有这一类题目啊!
考虑求出每种连通块对答案的贡献,对于一个大小大于 的连通块 ,求出与 中点有直接连边但是不属于 的节点个数 ,那么 造成贡献的概率是 。
理由的话可以考虑只有在 个节点都被删掉之后,连通块 才是独立的,否则它就不是连通块 了。我们要求的是对于每种独立连通块的贡献,不然可能会算重。
由期望的线性性,直接把所有连通块造成贡献的概率加起来就行了。
现在考虑 DP 一下贡献,发现 的贡献只和 与 有关,把这两个东西刻画入状态里面做树形 DP 就行了, 表示以 为根的子树,子树内(强行钦定 必选)选了 个节点作为连通块,且 的方案数。背包一下即可,写得好看一点可以做到 注意别写得太难看。
谨记连通块大小严格大于而非大于等于 。
#include<bits/stdc++.h>
using namespace std;
const int N=110;
const int mod=998244353;
struct modint {
int val;
static int norm(const int& x) { return x < 0 ? x + mod : x; }
modint inv() const {
int a = val, b = mod, u = 1, v = 0, t;
while (b > 0) t = a / b, swap(a -= t * b, b), swap(u -= t * v, v);
return modint(u);
}
modint() : val(0) {}
modint(const int& m) : val(norm(m)) {}
modint(const long long& m) : val(norm(m % mod)) {}
modint operator-() const { return modint(norm(-val)); }
modint& operator+=(const modint& o) { return val = (1ll * val + o.val) % mod, *this; }
modint& operator-=(const modint& o) { return val = norm(1ll * val - o.val), *this; }
modint& operator*=(const modint& o) { return val = static_cast<int>(1ll * val * o.val % mod), *this; }
modint operator-(const modint& o) const { return modint(*this) -= o; }
modint operator+(const modint& o) const { return modint(*this) += o; }
modint operator*(const modint& o) const { return modint(*this) *= o; }
friend std::ostream& operator<<(std::ostream& os, const modint a) { return os << a.val; }
}f[N][N][N],g[N][N],ans;
int n,k,siz[N];vector < int > v[N];
template < int Max >
struct Choose{
modint frac[Max+10],inv[Max+10];
Choose(){
frac[0]=inv[0]=1;for(int i=1;i<=Max;++i) frac[i]=frac[i-1]*i;
inv[Max]=frac[Max].inv();for(int i=Max-1;i;--i) inv[i]=inv[i+1]*(i+1);
}
modint* operator [](const int x){return x?frac:inv;}
modint operator ()(const int x,const int y){return x<y||y<0?0:frac[x]*inv[y]*inv[x-y];}
};
Choose < N*N > C;
inline modint Calc(int x,int y){
return C[1][x]*C[1][y]*C[0][x+y];
}
void dfs(int x,int y){
f[x][1][v[x].size()]=1;siz[x]=1;
for(int i:v[x]){
if(i==y) continue;
dfs(i,x);
for(int j=0;j<=siz[x];++j) for(int k=0;k<=n;++k) g[j][k]=f[x][j][k];
for(int j=1;j<=siz[x];++j){
for(int k=1;k<=n;++k){
for(int a=1;a<=siz[i];++a){
for(int b=1;b<=n;++b){
f[x][j+a][k+b-2]+=g[j][k]*f[i][a][b];
}
}
}
}
siz[x]+=siz[i];
}
for(int i=k;i<=siz[x];++i) for(int j=0;j<=n;++j) ans+=f[x][i][j]*Calc(i,j);
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>k;++k;for(int i=1,x,y;i<n;++i){cin>>x>>y;v[x].emplace_back(y);v[y].emplace_back(x);}
dfs(1,0);
// modint res=0;
// for(int i=1;i<=n;++i){
// for(int j=k;j<=siz[i];++j){
// for(int l=0;l<=n;++l){
// if(f[i][j][l].val) cout<<i<<' '<<j<<' '<<l<<' '<<f[i][j][l]<<' '<<Calc(j,l)<<endl;
// res+=f[i][j][l]*Calc(j,l);
// }
// }
// }
cout<<ans<<endl;
return 0;
}