[BZOJ1430]小猴打架
树的 prufer 编码的弱版模板题。
Problem
题目描述
一开始森林里面有
每次打完架后,打架的双方以及它们的好朋友就会互相认识,成为好朋友。
经过
现在的问题是,总共有多少种不同的打架过程。
比如当{1-2,1-3}{1-2,2-3}{1-3,1-2}{1-3,2-3}{2-3,1-2}{2-3,1-3}
六种不同的打架过程。
输入格式
一个整数
输出格式
一行,方案数
输入
4
输出
96
说明 / 提示
Code
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#define mod 9999991#define LL long longusing namespace std;inline LL quickpow(LL a,LL b){ LL ans=1; while(b) { if(b&1)ans=(ans*a)%mod; a=(a*a)%mod; b>>=1; } return ans;}int main(void){ int i,n; LL ans; scanf("%d",&n); ans=quickpow(n,n-2); for(i=1;i<n;++i)ans=(ans*i)%mod; printf("%lld\n",ans); return 0;}