• 31 October


    https://www.cnblogs.com/RabbitHu/p/51nod1353.html

    树形 DP 求所有联通块 (ge K) 的方案数.

    切断:(forall iinleft[1, s_u ight]), (displaystyle f(u, i) =sum_{j=1}^{s_v} f(v, j) =f(v, 0)).

    不切断:(forall iinleft[1, s_u ight]), (displaystyle sum_{j=1}^{s_v}f(u, i+j) = f(u, i) f(v, j)).

    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;
    
  • 相关阅读:
    POJ 1511
    POJ 1125
    POJ 2240
    POJ 1459
    POJ 1274
    POJ 1789
    POJ 2485,1258
    POJ 1236
    POJ 1273
    Ruby on Rails 观后感
  • 原文地址:https://www.cnblogs.com/greyqz/p/11769567.html
Copyright © 2020-2023  润新知