zoukankan      html  css  js  c++  java
  • 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)! ullet n^n}{2} ullet sum_{k = 3}^n frac{1}{n^k(n-k)!}$$
    证明我们可以采用算两次的方法进行证明:
    (g(n,k))表示由(k)棵有根数组成的,节点数为(n)且带标号的图的个数,不妨设边的方向都是由父亲指向儿子。
    再令(h(n,k))表示有多少种长度为(n-k)有向边的序列,使得按这个顺序加边后刚好会构成由(k)棵根树构成的节点带有标号的图。则我们可以得到(h(n,k))的一种计算方法

    [h(n,k) = g(n,k) imes (n-k)! ]

    这个式子不难得到。我们在考虑另一种方法——每次选出一条边,其中这条边由一个点连向非他自己所属有根树的根(初始每个点自己就是一棵树),每增加一条边就会减少一棵树。故有

    [h(n,k) = n(n-1) imes n(n-2) imes cdots imes nk = n^{n-k} imes frac{(n-1)!}{(k-1)!} ]

    于是有$$g(n,k) imes (n-k)! = n^{n-k} imes frac{(n-1)!}{(k-1)!}$$
    解得$$g(n,k) = n^{n-k} imes inom{n-1}{k-1}$$
    之后考虑如何用(g(n,k))(f(n))。由于(n)个点(n)条边的无向连通图一定有且只有(1)个环。我们可以枚举环的长度(k),然后把环看成根,就等同于环上套了(k)棵有根树。从(3)开始枚举环的长度,便有

    [f(n) = sum_{k=3}^n(g(n,k) imes frac{(n-1)!}{2}) ]

    其中(frac{(k-1)!}{2})(k)个数排成一个圈的本质不同排列数。
    于是将$$g(n,k) = n^{n-k} imes inom{n-1}{k-1}$$代入,便可得到开始的公式了。
    由于SGU目前不可提交,所以没有代码。

  • 相关阅读:
    第三套三
    多线程读写共享变量时,synchronized与volatile的作用
    jQuery源代码学习笔记:构造jQuery对象
    写入位置时发生訪问冲突
    Free Editor
    大区间素数筛选 POJ2689
    HDU
    CentOS下挂载U盘
    得到当前堆栈信息的两种方式(Thread和Throwable)的纠结
    [实战]MVC5+EF6+MySql企业网盘实战(9)——编辑文件名
  • 原文地址:https://www.cnblogs.com/mmlz/p/6184039.html
Copyright © 2011-2022 走看看