SGU481 Hero of Our Time
Description
Saratov ACM ICPC teams have a tradition to come together on Halloween and recollect terrifying stories. And the most popular story among the newcomers is the story about the "Mescher Tree". A long time ago, when the famous Dmitry Mescheryakov aka Mescher was very young and he even didn't know how to write Dijkstra algorithm, he faced a difficult problem with a tree. Input file contained \(n\) — the number of vertices, and pairs of vertices, connected with an edge. Without thinking a lot (honestly, the exact reason of that mistake is unknown), he wrote the following code:
read(n);
for i := 1 to n do begin
read(u, v);
g[u, v] := true;
g[v, u] := true;
end;
Mescher successfully compiled his code, got WA on sample test and started long debugging... This story has become a true legend. So it's no surprise that Saratov ACM ICPC teams use the following definition: connected undirected graph with n vertices and n edges is called Mescheryakov Tree or, less formally, Mescher Tree. The area of application of Mescher trees is not well-studied, so we suggest you to solve one of the problems connected with such trees: given n, find the number of distinct Mescher trees with \(n\) vertices. Trees are labeled, i.e. two trees are considered distinct if and only if their adjacency matrices differ.
Input
Input contains single integer number \(n (3 \le n \le 5000)\).
Output
Output the number of Mescher trees with \(n\) vertices without leading zeroes.
Sample Input
3
Sample Output
1
这是一个比较经典的题目,即求\(n\)个点\(n\)条边的有标号无向连通图的个数。
我们设\(f(n)\)为答案,那么有$$f(n) = \frac{(n-1)! \bullet n^n}{2} \bullet \sum_{k = 3}^n \frac{1}{n^k(n-k)!}$$
证明我们可以采用算两次的方法进行证明:
设\(g(n,k)\)表示由\(k\)棵有根数组成的,节点数为\(n\)且带标号的图的个数,不妨设边的方向都是由父亲指向儿子。
再令\(h(n,k)\)表示有多少种长度为\(n-k\)有向边的序列,使得按这个顺序加边后刚好会构成由\(k\)棵根树构成的节点带有标号的图。则我们可以得到\(h(n,k)\)的一种计算方法
\]
这个式子不难得到。我们在考虑另一种方法——每次选出一条边,其中这条边由一个点连向非他自己所属有根树的根(初始每个点自己就是一棵树),每增加一条边就会减少一棵树。故有
\]
于是有$$g(n,k) \times (n-k)! = n^{n-k} \times \frac{(n-1)!}{(k-1)!}$$
解得$$g(n,k) = n^{n-k} \times \binom{n-1}{k-1}$$
之后考虑如何用\(g(n,k)\)求\(f(n)\)。由于\(n\)个点\(n\)条边的无向连通图一定有且只有\(1\)个环。我们可以枚举环的长度\(k\),然后把环看成根,就等同于环上套了\(k\)棵有根树。从\(3\)开始枚举环的长度,便有
\]
其中\(\frac{(k-1)!}{2}\)是\(k\)个数排成一个圈的本质不同排列数。
于是将$$g(n,k) = n^{n-k} \times \binom{n-1}{k-1}$$代入,便可得到开始的公式了。
由于SGU目前不可提交,所以没有代码。
SGU481 Hero of Our Time的更多相关文章
- H5游戏开发之Stick Hero
自从上次发布一个小恐龙游戏以后,到现在10天了,前后又写了3个游戏,挑了一个感觉比较有挑战的游戏和大家分享一下. 效果演示 这是我模拟一个苹果游戏<stick hero>游戏写的一个小游戏 ...
- BZOJ 1191 超级英雄 Hero 题解
BZOJ 1191 超级英雄 Hero 题解 Description 现在电视台有一种节目叫做超级英雄,大概的流程就是每位选手到台上回答主持人的几个问题,然后根据回答问题的多少获得不同数目的奖品或奖金 ...
- 2016HUAS暑假集训训练2 K - Hero
题目链接:http://acm.hust.edu.cn/vjudge/contest/121192#problem/K 这也是一道贪心题,刚开始写时以为只要对每一敌人的攻击和血的乘积进行从小到大排序即 ...
- 【入门】匈牙利算法+HNOI2006 hero超级英雄
一.关于匈牙利算法 匈牙利算法是由匈牙利数学家Edmonds提出的,用增广路径求二分图最大匹配的算法. 听起来高端,其实说白了就是: 假设不存在单相思(单身狗偷偷抹眼泪),在一个同性恋不合法的国家里( ...
- 2016HUAS_ACM暑假集训2K - Hero(英雄)
这也属于一个贪心题.关键是排序的依据. 这题排序的依据是敌人的伤害/血量(DPS/HP),不难证明,当这个比值相同时,不论先解决谁效果是相同的.思路大部分在注释里. 题目大意: 假设你的血量无限,但是 ...
- bzoj 1191: [HNOI2006]超级英雄Hero
1191: [HNOI2006]超级英雄Hero Time Limit: 10 Sec Memory Limit: 162 MB 二分图匹配... Description 现在电视台有一种节目叫做超 ...
- HDU 4901 The Romantic Hero
The Romantic Hero Time Limit: 3000MS Memory Limit: 131072KB 64bit IO Format: %I64d & %I64u D ...
- HDU4901 The Romantic Hero 计数DP
2014多校4的1005 题目:http://acm.hdu.edu.cn/showproblem.php?pid=4901 The Romantic Hero Time Limit: 6000/30 ...
- HDU 4310 Hero (贪心算法)
A - Hero Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit Sta ...
随机推荐
- 关于Git中的一些常用的命令
深入了解git的checkout命令 检出命令(git checkout)是Git最常用的命令之一,同时也是一个很危险的命令. 因为这条命令会重写工作区.检出命令的用法如下: 用法一: git che ...
- Lua - 基础语法
Hello World 交互式编程 Lua 交互式编程模式可以通过命令 lua -i 或 lua 来启用: [huey@huey-K42JE lua]$ lua Lua 5.1.4 Copyright ...
- SDK 组件 Qupaisdk 启动出错,错误消息为 [Qupaisdk], the android stack error message is Fail to start the plugin, which is caused by Failed resolution of: Lcom/duanqu/qupai/recorder/R$array;
紧急解决办法: 将你的oneSDK(qupaiSDK)里面的manifest的pageckage改为:com.duanqu.qupai.recorder
- HW-IP合法性_Java
描述 现在IPV4下用一个32位无符号整数来表示,一般用点分方式来显示,点将IP地址分成4个部分,每个部分为8位,表示成一个无符号整数(因此不需要用正号出现),如10.137.17.1,是我们非常熟悉 ...
- sql 更新重复数据只取一条记录
select s.* from ( select *, row_number() over (partition by PersonnelAccount order BY Personnel ...
- SQL语句与正则表达式
今儿个才知道SQL语句还可以搭配正则表达式作为查询条件,很是有用. REGEXP_LIKE(匹配)REGEXP_INSTR (包含)REGEXP_REPLACE(替换)REGEXP_SUBSTR(提取 ...
- C++异常处理(Exception Handling)
在C++中引入了三种操作符来处理程序的出错情况,分别是:try , throw , catch 1.基本的用法如下: try{ //code to be tried throw exceptio ...
- (CodeForces 510C) Fox And Names 拓扑排序
题目链接:http://codeforces.com/problemset/problem/510/C Fox Ciel is going to publish a paper on FOCS (Fo ...
- 浅谈mysql中不同事务隔离级别下数据的显示效果
事务的概念 事 务是一组原子性的SQL查询语句,也可以被看做一个工作单元.如果数据库引擎能够成功地对数据库应用所有的查询语句,它就会执行所有查询,如果任何一条查 询语句因为崩溃或其他原因而无法执行,那 ...
- Winform窗口弹出位置控制
窗体的弹出位置可以由属性StartPosition来指定,默认值有: Manural 自定义,由属性Location指定: CenterScreen 屏幕中央: WindowsDefaultBound ...