bzoj1430 小猴打架 prufer 序列
题目传送门
https://lydsy.com/JudgeOnline/problem.php?id=1430
题解
prufer 序列模板题。
一个由 \(n\) 个点构成的有标号无根树的个数为 \(n^{n-2}\)。
证明就是 prufer 序列,可以看我的学习笔记。
https://www.cnblogs.com/hankeke/p/prufer.html
然后因为一棵树的加边顺序随意,所以还需要乘上 \((n-1)!\)。
所以最后答案为 \(n^{n-2}(n-1)!\)。
#include<bits/stdc++.h>
#define fec(i, x, y) (int i = head[x], y = g[i].to; i; i = g[i].ne, y = g[i].to)
#define dbg(...) fprintf(stderr, __VA_ARGS__)
#define File(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
#define fi first
#define se second
#define pb push_back
template<typename A, typename B> inline char smax(A &a, const B &b) {return a < b ? a = b , 1 : 0;}
template<typename A, typename B> inline char smin(A &a, const B &b) {return b < a ? a = b , 1 : 0;}
typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> pii;
template<typename I> inline void read(I &x) {
int f = 0, c;
while (!isdigit(c = getchar())) c == '-' ? f = 1 : 0;
x = c & 15;
while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c & 15);
f ? x = -x : 0;
}
const int P = 9999991;
int n;
inline void work() {
int ans = 1;
for (int i = 1; i <= n - 2; ++i) ans = (ll)ans * n % P;
for (int i = 1; i <= n - 1; ++i) ans = (ll)ans * i % P;
printf("%d\n", ans);
}
inline void init() {
read(n);
}
int main() {
#ifdef hzhkk
freopen("hkk.in", "r", stdin);
#endif
init();
work();
fclose(stdin), fclose(stdout);
return 0;
}
bzoj1430 小猴打架 prufer 序列的更多相关文章
- BZOJ1430小猴打架——prufer序列
题目描述 一开始森林里面有N只互不相识的小猴子,它们经常打架,但打架的双方都必须不是好朋友.每次打完架后,打架 的双方以及它们的好朋友就会互相认识,成为好朋友.经过N-1次打架之后,整个森林的小猴都会 ...
- [bzoj1430]小猴打架_prufer序列
小猴打架 bzoj-1430 题目大意:题目链接. 注释:略. 想法: 我们发现打架的情况就是一棵树. 我们只需要把确定树的形态然后乘以$(n-1)!$表示生成这棵树时边的顺序. 一共$n$个节点我们 ...
- 【bzoj1430】小猴打架 Prufer序列
题目描述 给出 $n$ 个点,每次选择任意一条边,问这样 $n-1$ 次后得到一棵树的方案数是多少. 输入 一个整数N. 输出 一行,方案数mod 9999991. 样例输入 4 样例输出 96 题解 ...
- [BZOJ1430] 小猴打架 (prufer编码)
Description 一开始森林里面有N只互不相识的小猴子,它们经常打架,但打架的双方都必须不是好朋友.每次打完架后,打架的双方以及它们的好朋友就会互相认识,成为好朋友.经过N-1次打架之后,整个森 ...
- bzoj1430: 小猴打架(prufer序列)
1430: 小猴打架 题目:传送门 简要题意: n只互不相识的猴子打架,打架之后就两两之间连边(表示已经相互认识),只有不认识(朋友的朋友都是朋友)的两只猴子才会打架.最后所有的猴子都会连成一棵树,也 ...
- bzoj 1430 小猴打架 prufer 性质
小猴打架 Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 709 Solved: 512[Submit][Status][Discuss] Descri ...
- BZOJ1430: 小猴打架
1430: 小猴打架 Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 328 Solved: 234[Submit][Status] Descripti ...
- bzoj 1430: 小猴打架 -- prufer编码
1430: 小猴打架 Time Limit: 5 Sec Memory Limit: 162 MB Description 一开始森林里面有N只互不相识的小猴子,它们经常打架,但打架的双方都必须不是 ...
- 【prufer编码】BZOJ1430 小猴打架
Description 一开始森林里面有N只互不相识的小猴子,它们经常打架,但打架的双方都必须不是好朋友.每次打完架后,打架的双方以及它们的好朋友就会互相认识,成为好朋友.经过N-1次打架之后,整个森 ...
随机推荐
- zepto-touch.js插件
/* Zepto v1.2.0 - zepto event ajax form ie - zeptojs.com/license */(function(global, factory) { if ( ...
- Customizable Route Planning
w https://www.microsoft.com/en-us/research/wp-content/uploads/2011/05/crp-sea.pdf 1 Introduction The ...
- customizable route planning 工业界地图产品的路径规划
https://www.microsoft.com/en-us/research/publication/customizable-route-planning/?from=http%3A%2F%2F ...
- Oracle编程艺术--配置环境
如何设置login.sql,参照了本书作者的意见,我也大概弄明白了 只是该文件的存放位置一直就出错,百度了很久,说是$ORACLE_HOME/sqlplus/admin/glogin.sql(默认)于 ...
- kafka 配置权限
参考:https://www.cnblogs.com/huxi2b/p/10437844.html http://kafka.apache.org/documentation/#security_au ...
- tensorflow 关于 矩阵 运算 + 符号得含义。 2维 数组 + 1纬数组, 就是每一行都 加一边 1纬数组。 呵呵
小锋子Shawn(403568338) 13:51:23mnist.training.images?墨须(964489899) 13:51:27我的图片是100*100的,该怎么兼容. 小锋子S ...
- lua-resty-kafka erro xxxx could not be resolved (3: Host not found)
问题:使用 lua-resty-kafka 向 kafka 发送数据失败,报错如下: slave6 could not be resolved (: Host not found) 配置信息: lua ...
- SpringCloud启动Eureka server时报错 java.lang.TypeNotPresentException: Type javax.xml.bind.JAXBContext not present
SpringBoot打开Eureka server时出现以下错误: java.lang.TypeNotPresentException: Type javax.xml.bind.JAXBContext ...
- centos yum 安装php5.6
centos yum 安装php5.6 卸载 php之前的版本: yum remove -y php-common 配置源 CentOS 6.5的源 rpm -Uvh http://ftp.iij.a ...
- 数模常用算法系列Matlab实现-----线性规划
线性规划的 Matlab 标准形式 线性规划的目标函数可以是求最大值,也可以是求最小值,约束条件的不等号可以是小于号也可以是大于号.为了避免这种形式多样性带来的不便,Matlab 中规定线性 规划的标 ...