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 ...
随机推荐
- cgi表单的处理
在HTML中,当客户填写了表单,并按下了发送(submit)按钮后,表单的内容被发送 到了服务器端,一般的,这时就需要有一个服务器端脚本来对表单的内容进行一些处理, 或者是把它们保存起来,或者是按内容 ...
- Yii2查询语句使用不等于号
Yii2 Active Record查询条件使用不等于号,需要使用到 operator format: [operator, operand1, operand2, ...] 运算符格式: [运算符, ...
- 【转】The content of element type "configuration" must match "(properties?,settings?,typeAliases?,typeHandlers?,objectFactory?...
[转]The content of element type "configuration" must match "(properties?,settings?,typ ...
- 使用MVCJqGrid的心得
最近公司网站进行升级,项目要用.net mvc,mysql和轻量级orm框架dapper.由于美工页面出不来啊,让我先写简单写写后台的列表,同事说用MvcJqGrid,也得到了架构的同意. 可是不得不 ...
- dll不同的调用方式
LoadLibrary 一般是动态加载DLL时(你并不需要对应的头文件,和LIB) #pragma comment 一般是静态加载DLL时(对应的头文件.DLL,和LIB缺一不可,并且生产的EXE没有 ...
- 解决IIS7中出现An error occurred on the server when processing the URL错误提示的方法
相信用过IIS7的朋友在调试程序的时候都遇到过下面这样的错误提示: An error occurred on the server when processing the URL. Please ...
- ###Linux基础 - 3
点击查看Evernote原文. #@author: gr #@date: 2014-10-15 #@email: forgerui@gmail.com 一.GCC编译程序 在Windows下使用Vis ...
- Harry Potter
Names appearing in "Harry Potter" 1.Harry Potter ①Harry is from Henry. ②Harry is related t ...
- 学习C++ Primer 的个人理解(九)
这一章介绍顺序容器,在之前的第三章中,了解到的vector就属于顺序容器的一种. 一个容器就是一些特定类型对象的集合. 除了vector,还有哪些顺序容器? vector: 大小可变,随机访问的速度很 ...
- Basic MSI silent install
Articles and post about silent install for Basic MSI, InstallScript, InstallScript MSI: Silent-mode ...