bzoj 1430: 小猴打架 (prufer序列+数论)
2017-04-18 11:27
441 查看
题目描述
传送门
题目大意:N个点,每次可以连接两个不连通的点,N-1次后形成一棵树,问题有多少种不同的连接方式。题解
首先确定有多少种不同形态的树。根据prufer序列,设有m个点的度数无限制,那么贡献是Cmn−2mn−2−tot那么对于这道题来说,树的形态就是nn−2
因为n-1条边还存在连接的顺序,所以最后的答案是nn−2∗(n−1)!
代码
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #define N 1000003 #define p 9999991 #define LL long long using namespace std; int n; LL quickpow(LL num,int x) { LL ans=1; LL base=num%p; while (x) { if (x&1) ans=ans*base%p; x>>=1; base=base*base%p; } return ans; } int main() { freopen("a.in","r",stdin); scanf("%d",&n); LL ans=1; for (int i=1;i<=n-1;i++) ans=(LL)ans*i%p; ans=ans*quickpow(n,n-2)%p; printf("%lld\n",ans); }
相关文章推荐
- [BZOJ1430]小猴打架(prufer序列+数学相关)
- bzoj1430 小猴打架(prufer序列+计数)
- bzoj1430: 小猴打架(prufer序列)
- 【bzoj1430】小猴打架 Prufer序列
- prufer序列 图论?组合数学? BZOJ1430 小猴打架
- prufer编码 与 bzoj1430小猴打架 ——by lethalboy
- 【prufer编码】BZOJ1430 小猴打架
- BZOJ.1430.小猴打架(Prufer)
- BZOJ 1430 小猴打架 - prufer编码
- 【BZOJ 1430】 1430: 小猴打架 (Prufer数列)
- bzoj 1430: 小猴打架 -- prufer编码
- 【bzoj1430】小猴打架
- [bzoj1430]小猴打架 水题
- BZOJ1430 小猴打架
- 【BZOJ1430】小猴打架(Prufer编码)
- bzoj 1430: 小猴打架
- BZOJ-1430 小猴打架
- 【BZOJ】【1430】小猴打架
- BZOJ 1430: 小猴打架
- BZOJ1430: 小猴打架