UVA 11609 - Anne's game cayley定理
Lily: “Chantarelle was part of my exotic phase.”
Buffy: “It’s nice. It’s a mushroom.”
Lily: “It is? That’s really embarrassing.”
Buffy: “Well, it’s an exotic mushroom, if that’s any comfort.”
Joss Whedon, "Anne".
A little girl whose name is Anne Spetring likes to play the following game. She draws a circle on
paper. Then she draws another one and connects it to the first cicrle by a line. Then she draws another
and connects it to one of the first two circles by a line. She continues this way until she has n circles
drawn and each one connected to one of the previously drawn circles. Her circles never intersect and
lines never cross. Finally, she numbers the circles from 1 to n in some random order.
How many different pictures can she draw that contain exactly n circles? Two pictures are different
if one of them has a line connecting circle number i to circle number j, and the other picture does not.
Input
The first line of input gives the number of cases, N. N test cases follow. Each one is a line containing
n (0 < n ≤ 100).
Output
For each test case, output one line containing ‘Case #x:’ followed by X, where X is the remainder
after dividing the answer by 2000000011.
Sample Input
3
1
2
3
Sample Output
Case #1: 1
Case #2: 1
Case #3: 3
题意:给出n,问说有n个节点构成的标号树有多少种。
题解:此定理说明用n-1条边将n个一致的顶点连接起来的联通树的个数为n^(n-2),也可以这样,将n个城市连接起来的树状公路网络有n^(n-2)种方案。所谓树状,指的是用n-1条边将n个顶点构成一个连通图。当然,建造一个树状的公路网络将n个城市连接起来,应求其中长度最短、造价最省的一种,或效益最大的一种。Cayley定理只是说明可能方案的数目。
//meek
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include<map>
#include<queue>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair const int N=;
const ll INF = 1ll<<;
const int inf = ;
const int MOD = ; ll quick_pow(ll x,ll p) {
if(!p) return ;
ll ans = quick_pow(x,p>>);
ans = ans*ans%MOD;
if(p & ) ans = ans*x%MOD;
return ans;
}
int main() {
int cas;
ll n;
scanf("%d",&cas);
for(int i=;i<=cas;i++) {
scanf("%lld",&n);
if(n< 2ll) printf("Case #%d: %lld\n",i,1ll);
else printf("Case #%d: %lld\n",i,quick_pow(n,n-));
}
return ;
}
daima
UVA 11609 - Anne's game cayley定理的更多相关文章
- Nyoj 星际之门(一)(Cayley定理)
描述 公元3000年,子虚帝国统领着N个星系,原先它们是靠近光束飞船来进行旅行的,近来,X博士发明了星际之门,它利用虫洞技术,一条虫洞可以连通任意的两个星系,使人们不必再待待便可立刻到达目的地. 帝国 ...
- Codeforces1113F. Sasha and Interesting Fact from Graph Theory(组合数学 计数 广义Cayley定理)
题目链接:传送门 思路: 计数.树的结构和边权的计数可以分开讨论. ①假设从a到b的路径上有e条边,那么路径上就有e-1个点.构造这条路径上的点有$A_{n-2}^{e-1}$种方案: ②这条路径的权 ...
- prufer编码 cayley定理
背景(在codeforces 917D 报废后,看题解时听闻了这两个玩意儿.实际上917D与之“木有关西”,也可以认为是利用了prufer的一些思路.) 一棵标号树的Pufer编码规则如下:找到标号最 ...
- 图论:Prufer编码-Cayley定理
BZOJ1430:运用Cayley定理解决树的形态统计问题 由Prufer编码可以引申出来一个定理:Cayley 内容是不同的n结点标号的树的数量为n^(n-2) 换一种说法就是一棵无根树,当知道结点 ...
- Prüfer序列和cayley定理
参考资料: 1.matrix67 <经典证明:Prüfer编码与Cayley公式> 2.百度百科 3.Forget_forever prufer序列总结 4.维基百科 5.dirge的学习 ...
- luogu P4430 小猴打架(prufer编码与Cayley定理)
题意 n个点问有多少种有顺序的连接方法把这些点连成一棵树. (n<=106) 题解 了解有关prufer编码与Cayley定理的知识. 可知带标号的无根树有nn-2种.然后n-1条边有(n-1) ...
- 偶然遇见:Cayley定理
看到\(purfer\)序列板子后,想到这个名词在哪见过,于是找到了一个题,还带出一个: \(T1\). 题目链接:P4430 小猴打架 开始极其懵逼,考虑过大力容斥,但还是失败了,原来是: Cayl ...
- Cayley 定理与扩展 Cayley 定理
Cayley 定理 节点个数为 \(n\) 的无根标号树的个数为 \(n^{n−2}\) . 这个结论在很多计数类题目中出现,要证明它首先需要了解 \(\text{Prufer}\) 序列的相关内容. ...
- uva 10733 The Colored Cubes<polya定理>
链接:http://uva.onlinejudge.org/external/107/10733.pdf 题意: N 种颜色可以涂成多少种立方体~ 思路: 使正六面体保持不变的运动群总共有: 1.不变 ...
随机推荐
- MySQL实现表之间的字段更新
新功能写好之后,需要把以前表数据更新一下,字段数据从以前的表中获取,只更新两个字段 UPDATE TABLE1,TABLE2 SET TABLE1.COLUMN1 = TABLE2.COLUMN1 , ...
- vue2.0项目中使用Ueditor富文本编辑器应用中出现的问题
1.如何设置config中的内容 readonly:true,//只读模式wordCount:false,//是否开启字数统计enableAutoSave: false,//自动保存功能 重点:ena ...
- Android中图片旋转
Activity_main.xml文件配置 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/androi ...
- mysqldump+mydumper+xtrabackup备份原理流程
mysqldump备份原理 备份的基本流程如下: 1.调用FTWRL(flush tables with read lock),全局禁止读写 2.开启快照读,获取此时的快照(仅对innodb表起作用) ...
- 最简单的一致性Hash算法实现
import java.util.Collection;import java.util.SortedMap;import java.util.TreeMap; public class Consis ...
- AngularJS指令进阶 -- ngModelController详解
大家都知道AngularJS中的指令是其尤为复杂的一个部分,但是这也是其比较好玩的地方.这篇文章我们就来说一说如何在我们自定义的指令中,利用ngModel的controller来做双向数据绑定,本文对 ...
- vs code格式化代码快捷键
windows:shift+alt+F ubuntu: ctrl+shift+i
- python简单的输入与输出
1 首先利用python完成简单的输出,运行如下: python和c语言类似,但又有所不同,python开发快,语言简洁,我是这样对比学的 输出:print+空格+'要输出的内容',一定要是英文状态下 ...
- ack 工具
ack-tools ack其实就是快速查找工具,但centos在没有这个安装包. 下载安装 cd /tmp git clone https://github.com/dongci/ack.git cd ...
- 洛谷P1297 [国家集训队]单选错位_数学期望
考虑第 iii 位, 那么当前共有 a[i]a[i]a[i] 种选项,那么当前选项正确的情况就是下一个被误填的答案与当前答案相同.换句话说,当前答案一共有 a[i]a[i]a[i] 种可能,而下一个答 ...