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.不变 ...
随机推荐
- javascript设计模式-单体模式
场景:假设有一个Girl(美女)实体,该实体拥有姓名.年龄两个属性,拥有显示姓名和洗澡两个方法,下面分步骤构造该实体. 1.用简单基本单体模式: var Girl1 = { name:"昭君 ...
- A - Antipalindrome
Problem description A string is a palindrome if it reads the same from the left to the right and fro ...
- Ubuntu16.04系统下汉字显示为方框解决办法(图文详解)
不多说,直接上干货! 问题详情 问题分析 今天一打开Ubuntu系统,竟然不支持中文显示了.开始时以为是搜狗拼音的问题,然后重装了一遍fcitx,然后用重装了一遍搜狗输入法.可是重装后问题根本没有解决 ...
- C# 添加应用程序包
项目中可能会遇到某些扩展方法不可以应用的情况,这时候需要在项目中引用程序包 步骤如下: 回车即可
- java8-1-interface接口
Java 8 允许我们使用default关键字,为接口声明添加非抽象的方法实现.这个特性又被称为扩展方法 sample: interface Formula { double calculate(in ...
- MSSQL_20160719_在作业步骤中使用sp_send_dbmail遇到的问题
需求: 在作业步骤中使用sp_send_dbmail发出邮件, 并将数据库中的日志表通过@query参数导出文本作为邮件附件 遇到错误: 服务器 DB-DWH-1,第 1 行 服务器主体 " ...
- ZBrush中的PolyPainting如何理解?
什么是PolyPainting? PolyPainting在ZBrush ®中是一种创建纹理的方法,该方法通过对每个多边形顶点应用单一RGB值来着色模型.此方法无需使用UV坐标.通过直接对顶点应用颜色 ...
- 转载:rem的用法
本文属于转载,为尊重原作者的劳动成果,在此标注原文地址,点击此处浏览. 1.rem(font size of the root element)是指相对于根元素的字体大小的单位,em(font siz ...
- sass揭秘之@if,@for,@each(转载)
因为文章内含有很多sass代码,如需自己动手查看编译结果,推荐使用sassmeister这款在线编译工具,方便你阅读学习. 经过上两篇揭秘,大家心里对sass应该有了很好的认知感了,这篇文章基于前面两 ...
- 路飞学城Python-Day151
sprapy框架能够在pycharm中调试的方式 需要在配置文件中加上一个文件,文件的内容为 start.py #!/usr/bin/env python # -*- coding:utf-8 -*- ...