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定理的更多相关文章

  1. Nyoj 星际之门(一)(Cayley定理)

    描述 公元3000年,子虚帝国统领着N个星系,原先它们是靠近光束飞船来进行旅行的,近来,X博士发明了星际之门,它利用虫洞技术,一条虫洞可以连通任意的两个星系,使人们不必再待待便可立刻到达目的地. 帝国 ...

  2. Codeforces1113F. Sasha and Interesting Fact from Graph Theory(组合数学 计数 广义Cayley定理)

    题目链接:传送门 思路: 计数.树的结构和边权的计数可以分开讨论. ①假设从a到b的路径上有e条边,那么路径上就有e-1个点.构造这条路径上的点有$A_{n-2}^{e-1}$种方案: ②这条路径的权 ...

  3. prufer编码 cayley定理

    背景(在codeforces 917D 报废后,看题解时听闻了这两个玩意儿.实际上917D与之“木有关西”,也可以认为是利用了prufer的一些思路.) 一棵标号树的Pufer编码规则如下:找到标号最 ...

  4. 图论:Prufer编码-Cayley定理

    BZOJ1430:运用Cayley定理解决树的形态统计问题 由Prufer编码可以引申出来一个定理:Cayley 内容是不同的n结点标号的树的数量为n^(n-2) 换一种说法就是一棵无根树,当知道结点 ...

  5. Prüfer序列和cayley定理

    参考资料: 1.matrix67 <经典证明:Prüfer编码与Cayley公式> 2.百度百科 3.Forget_forever prufer序列总结 4.维基百科 5.dirge的学习 ...

  6. luogu P4430 小猴打架(prufer编码与Cayley定理)

    题意 n个点问有多少种有顺序的连接方法把这些点连成一棵树. (n<=106) 题解 了解有关prufer编码与Cayley定理的知识. 可知带标号的无根树有nn-2种.然后n-1条边有(n-1) ...

  7. 偶然遇见:Cayley定理

    看到\(purfer\)序列板子后,想到这个名词在哪见过,于是找到了一个题,还带出一个: \(T1\). 题目链接:P4430 小猴打架 开始极其懵逼,考虑过大力容斥,但还是失败了,原来是: Cayl ...

  8. Cayley 定理与扩展 Cayley 定理

    Cayley 定理 节点个数为 \(n\) 的无根标号树的个数为 \(n^{n−2}\) . 这个结论在很多计数类题目中出现,要证明它首先需要了解 \(\text{Prufer}\) 序列的相关内容. ...

  9. uva 10733 The Colored Cubes<polya定理>

    链接:http://uva.onlinejudge.org/external/107/10733.pdf 题意: N 种颜色可以涂成多少种立方体~ 思路: 使正六面体保持不变的运动群总共有: 1.不变 ...

随机推荐

  1. POJ 1386 判断欧拉回路

    题意:要开启一扇门,n个单词是密码,n个单词中,如果一个单词的首字母和前一个单词的尾字母相同,并且每个单词都能这么连起来且只用一次,则门可以开启,否则不能开启,现给出单词,判断门是否可以开. 有向图欧 ...

  2. 在windows系统下虚拟机和ubuntu系统的安装和卸载

    一.安装 之前有装过双系统,但是吧,一直用ubuntu系统,很久没进windows之后的某一天,自己再进windows,发现windows系统崩了,我也不知道为什么,找了很多方法没有解决,最后只好重装 ...

  3. XML DTD跟SCHEMA约束 语法了解

    dtd语法 元素: <!Element 元素名称 数据类型|包含内容> 数据类型: #PCDATA:普通文本 使用的时候一般用()引起来 包含内容: 该元素下可以出现哪些元素, 用()引起 ...

  4. hdu 2444 The Accomodation of Students 判断是否构成二分图 + 最大匹配

    此题就是求最大匹配.不过需要判断是否构成二分图.判断的方法是人选一点标记为红色(0),与它相邻的点标记为黑色(1),产生矛盾就无法构成二分图.声明一个vis[],初始化为-1.通过深搜,相邻的点不满足 ...

  5. 继承&封装

    扩展一个已有的类,并且继承该类的属性和行为这种方式成为继承. 实例 public class Polygon { public int sides; public double area; publi ...

  6. spring中log4j的使用---转载

    原文链接:http://www.codeceo.com/article/log4j-usage.html 日志是应用软件中不可缺少的部分,Apache的开源项目log4j是一个功能强大的日志组件,提供 ...

  7. Centos7 单节点安装 FastDFS + FastDHT服务

    Centos7 单节点安装 FastDFS + FastDHT服务 1.安装gcc(编译时需要) FastDFS是C语言开发,安装FastDFS需要先将官网下载的源码进行编译,编译依赖gcc环境,如果 ...

  8. Javaee 方法的构建和调用

    主类: package Szy02; public class Person { String name; int age; String sex; public Person(){ } public ...

  9. JS 100节楼梯,0-49节 分数等于节数 50以后(包括50)每节10分输入节数 得出分数

    var n = parseInt(prompt("请输入数值")); ; ; ){ ; i<n; i++) { sum = sum + i; } alert(sum); } ...

  10. CreateFile打开文件或者打开目录

    一.打开目录 参数列表: lpFileName String 要打开的文件的名字 dwDesiredAccess Long 如果为 GENERIC_READ 表示允许对设备进行读访问:如果为 GENE ...