Tag: INF pair scanf has root tree oid test i++ form Class
F-uniformly branched Trees
#include <bits/stdc++.h>#defineLL Long Long#defineFi first#defineSe Second#defineMk Make_pair#definePII Pair<int, int>#definePLI Pair<ll, int>#defineull unsigned long Longusing namespacestd;Const intN = 1e3 +7;Const intINF =0x3f3f3f3f;ConstLL INF =0x3f3f3f3f3f3f3f3f; LL dp[n][ One][n], Inv[n], f[n], finv[n], g[n][ One];intN, D, mod;voidinit () {inv[1] = f[0] = finv[0] =1; for(inti =2; i < N; i++) Inv[i] = (mod-mod/i) *inv[mod%i]%MoD; for(inti =1; i < N; i++) F[i] = f[i-1]*i%MoD; for(inti =1; i < N; i++) Finv[i] = finv[i-1]*inv[i]%MoD;}intMain () {scanf ("%d%d%d", &n, &d, &MoD); Init (); for(inti =0; I <= N; i++) dp[1][0][i] =1; for(inti =1; I <= D; i++) g[1][i] =1; for(inti =2; I <= N; i++) { for(intj =1; J <= D; J + +) { for(intK =1; K < I; k++) { for(intL =1; L <= J && L*k <= i; l++) {Dp[i][j][k]= (Dp[i][j][k] + 1ll*dp[i-l*k][j-l][k-1]*G[K][L])%MoD; } } for(intK =1; K <= N; k++) Dp[i][j][k] = (dp[i][j][k]+dp[i][j][k-1])%MoD; } g[i][1] = dp[i][d-1][n]; for(intj =2; J <= D; J + +) G[i][j]= g[i][j-1]* (dp[i][d-1][n]+j-1)%mod*inv[j]%MoD; } LL ans=0; if(N <=2) ans =1; ElseAns = dp[n][d][n/2]; if(N >2&&! (n&1) ) {ans= (ans + mod-dp[n/2][d-1][n/2] * (dp[n/2][d-1][n/2]-1) /2% MoD)%MoD; } printf ("%lld\n", ans); return 0;}/**/
Intel Code Challenge Final Round (div. 1 + div. 2, Combined) f-uniformly branched Trees no root tree with root tree +DP