prufer码水题
(n-2)!/[(d1-1)!*(d2-1)!*…*(dn-1)!]

 1 var c:array[0..200] of longint;
 2     x,n,i,j,s:longint;
 3     ans:int64;
 4 
 5 begin
 6   readln(n);
 7   if n=1 then
 8   begin
 9     readln(x);
10     if x=1 then writeln(0)
11     else writeln(1);
12     halt;
13   end;
14   for i:=1 to n do
15   begin
16     read(x);
17     if (x<1) or (x>n) then
18     begin
19       writeln(0);
20       halt;
21     end;
22     for j:=2 to x-1 do
23       inc(c[j]);
24     s:=s+x-1;
25   end;
26   if s<>n-2 then
27   begin
28     writeln(0);
29     halt;
30   end;
31   ans:=1;
32   for i:=2 to n-2 do
33   begin
34     ans:=ans*int64(i);
35     for j:=2 to n do
36     begin
37       while (c[j]>0) and (ans mod j=0) do
38       begin
39         dec(c[j]);
40         ans:=ans div j;
41       end;
42     end;
43   end;
44   writeln(ans);
45 end.
View Code

 

posted on 2015-01-16 22:45  acphile  阅读(109)  评论(0编辑  收藏  举报