Description
Solution
\ (n\) points of the two-fork-tree scheme number is \ (n!\)
The proof is very obvious: the new added points take up \ (1\) position, the new add \ (2\) position, then more out of a position, so the first \ (i\) points have \ (i\) kind of method
Consider the number of times each edge is passed, set the subtree size to \ (size\), or \ (size* (n-size) \)
To consider the number of times the parent edge of each point was passed, enumerate the subtree size
Then the contribution is the number of schemes of the inner shape of the subtree multiplied by the external pattern.
The interior is obviously \ (size!\) , but the number is not sure, so it is \ (size!*c_{n-i}^{size-1}\)
Outside we first determine a size of \ (i\) of the tree, and then the more out of the \ (n-size-i+1\) to spell up, the scheme number is \ (\frac{(n-j-1)!} {(i-2)!} \)
#include <bits/stdc++.h>using namespaceStdConst intn= .;intN,mod,c[n][n],fac[n],w[n][n];inline intFintXintY) {if(y<=0)return 1;returnW[x][y];}intMain () {Freopen ("Pp.in","R", stdin); Freopen ("Pp.out","W", stdout); cin>>n>>mod; for(intI=0; i<=n;i++) {c[i][0]=1; for(intj=1; j<=i;j++) c[i][j]= (c[i-1][j-1]+c[i-1][J])%mod; } fac[0]=1; for(intI=1; i<=n;i++) fac[i]=1ll*fac[i-1]*i%mod; for(intI=1; i<=n;i++) {w[i][0]=1; for(intj=1; j<=n;j++) w[i][j]=1ll*w[i][j-1]* (i+j-2)%mod; }intans=0; for(intI=2; i<=n;i++) for(intJ=n-i+1; j>=1; j--) ans= (ans+1ll*fac[j]*c[n-i][j-1]%mod*fac[i]%mod*f (i,n-j-i+1)%mod* (n-j)%mod*j)%mod; cout<<ans<<endl;return 0;}
Bzoj 5305: [Haoi2018] apple tree