版本比较
DP 好题
正文
增加 9 行删除 9 行
63 行未改动6465666768686970717239 行未改动1121131141151161161171181191205 行未改动12612712812913013013113213313412 行未改动14714814915015115215115215315415515613 行未改动1701711721731741741751761771788 行未改动18718818919019119219119219319419519611 行未改动20820921021121221221321421521628 行未改动63 行未改动
所以一定要割掉连接 $wz$ 和 $fa$ 的这条边且把 $fa$ 删掉的方案数,关于这个上面的转移也有了(把 $fa$ 当作 $wz$ 的一个儿子即可)。
注意:此时要拿 $g_{fa}$ 去计算 $ans$ 和 $g_{wz}$,而非 $f_{fa}$。
$4$
上代码:
39 行未改动 for(int t1=1;t1<=k;t1++) { int tzy=(1<<(t1-1)); if((tzy&S)==0||tzy<W||(tzy&W)!=0) continue; if(siz[j]-ge[W]==w[t1]) f[wz][S]=(f[wz][S]+f[j][W]*f[wz][S^W^tzy]%mod)%mod;//砍掉这棵子树满足第t1个条件 if(siz[j]-ge[W]==w[t1]) f[wz][S]=(f[wz][S]+f[j][W]*f[wz][S^W^tzy]%mod)%mod;//砍掉这棵子树满足第t1个条件 } } for(int t1=1;t1<=k;t1++) {5 行未改动 }}void dfs2(int wz,int last){
//把f[wz][S]对g[last][S]的贡献给删掉 for(int S=1;S<=o;S++) { for(int W=S;W>=1;W=((W-1)&S))12 行未改动 if((tzy&S)==0) continue; if(siz[wz]==w[t1]) g[last][S]=(g[last][S]%mod-g[last][S^tzy]%mod+mod)%mod; } } //换根DP
//换根DP for(int S=0;S<=o;S++) g[wz][S]=f[wz][S]; for(int S=o;S>=1;S--) {13 行未改动 if((tzy&S)==0) continue; if(n-siz[wz]==w[t1]) g[wz][S]=(g[wz][S]+g[wz][S^tzy])%mod; } } //计算贡献 //计算贡献 for(int W=o;W>=1;W=(W-1)&o) { for(int t1=1;t1<=k;t1++) {8 行未改动 if((tzy&o)==0) continue; if(n-siz[wz]==w[t1]) ans[wz]=(ans[wz]+f[wz][o^tzy])%mod; } ans1=(ans1+ans[wz])%mod; //把f[wz][S]对g[last][S]的贡献还给他
//把f[wz][S]对g[last][S]的贡献还给他 for(int S=o;S>=1;S--) { for(int W=S;W>=1;W=((W-1)&S)) {11 行未改动 if((tzy&S)==0) continue; if(siz[wz]==w[t1]) g[last][S]=(g[last][S]+g[last][S^tzy])%mod; } }
for(int i=0;i<e[wz].size();i++) if(e[wz][i]!=last) dfs2(e[wz][i],wz);}signed main()28 行未改动