1430: Little Monkey Fight Time limit:5 Sec Memory limit:162 MB
submit:335 solved:241
[Submit] [Status] Description at the beginning of the forest there are n strangers little monkeys, they often fight, but both sides of the fight must not be good friends. After each fight, both sides of the fight and their good friends will know each other and become good friends. After N-1 fights, all the little monkeys in the forest will be good friends. The question now is how many different fights there are in total. For example, when n=3, there are {1-2,1-3}{1-2,2-3}{1-3,1-2}{1-3,2-3}{2-3,1-2}{2-3,1-3} six different kinds of fight process. Input an integer n. Output line, number of scenarios mod 9999991. Sample Input4
Sample Output96
HINT
50% of Data n<=10^3.
100% of Data n<=10^6.
Source
Sum: ... This seems to me in addition to bzoj1000 the shortest bzoj program ... I first saw the "Little monkey Fight" the word, and then saw the "fight once after the two sides become friends", at first thought and look at the set, but when I saw how many kinds of play when I found that I think more ... Obviously, for N nodes of the spanning tree, the kind of n^ (N-2), because this problem seems to fight with the order to repeat the calculation, so again a n!/n, that is (N-1)!, so f (x) = (x-1)!*x^ (x-2) (Ah hehe witty I even fast power are lazy writing it?)
1 Constp=9999991;2 varI,j,k,m,n:longint;l:int64;3 begin4READLN (n); l:=1;5 fori:=1 toN-2 Dol:= (L*n)MoDp;6 forI:= (n1)Downto 1 Dol:= (L*i)MoDp;7 Writeln (l);8 End.
1430: Little Monkey Fights