zoukankan      html  css  js  c++  java
  • 【BZOJ1430】小猴打架(Prufer编码)

    题意:求n个点带编号生成树的不同加边序列个数

    n<=10^6

    思路:

    WJMZBMR:额。首先他们打架的关系是一颗无根树,就有n^(n-2)种情况,还有打架的顺序,是(n-1)!种,乘起来就可以了囧。。

     1 const mo=9999991;
     2 var n,k,i:longint;
     3     ans,y:int64;
     4 begin
     5  assign(input,'bzoj1430.in'); reset(input);
     6  assign(output,'bzoj1430.out'); rewrite(output);
     7  readln(n);
     8  k:=n-2; y:=n;
     9  ans:=1;
    10  while k>0 do
    11  begin
    12   if k and 1=1 then ans:=ans*y mod mo;
    13   y:=y*y mod mo;
    14   k:=k>>1;
    15  end;
    16  for i:=1 to n-1 do ans:=ans*i mod mo;
    17  writeln(ans);
    18  close(input);
    19  close(output);
    20 end.
  • 相关阅读:
    Counting Stars hdu
    Color it hdu
    steins;Gate
    原根
    3-idiots
    Tree
    洛谷P1352 没有上司的舞会
    洛谷P1131 时态同步
    洛谷P3177 树上染色
    Codeforces Round #617 (Div. 3)
  • 原文地址:https://www.cnblogs.com/myx12345/p/6478571.html
Copyright © 2011-2022 走看看