39 lines
830 B
Text
39 lines
830 B
Text
V nMax = 250
|
||
V nBranches = 4
|
||
V rooted = [BigInt(0)] * (nMax + 1)
|
||
V unrooted = [BigInt(0)] * (nMax + 1)
|
||
rooted[0] = BigInt(1)
|
||
rooted[1] = BigInt(1)
|
||
unrooted[0] = BigInt(1)
|
||
unrooted[1] = BigInt(1)
|
||
|
||
F choose(m, k)
|
||
I k == 1
|
||
R m
|
||
V result = m
|
||
L(i) 1 .< k
|
||
result = result * (m + i) I/ (i + 1)
|
||
R result
|
||
|
||
F tree(br, n, l, sum, cnt)
|
||
V s = 0
|
||
L(b) br + 1 .. :nBranches
|
||
s = sum + (b - br) * n
|
||
I s > :nMax {R}
|
||
|
||
V c = choose(:rooted[n], b - br) * cnt
|
||
|
||
I l * 2 < s {:unrooted[s] += c}
|
||
I b == :nBranches {R}
|
||
:rooted[s] += c
|
||
L(m) (n - 1 .< 0).step(-1)
|
||
tree(b, m, l, s, c)
|
||
|
||
F bicenter(s)
|
||
I (s [&] 1) == 0
|
||
:unrooted[s] += :rooted[s I/ 2] * (:rooted[s I/ 2] + 1) I/ 2
|
||
|
||
L(n) 1 .. nMax
|
||
tree(0, n, n, 1, BigInt(1))
|
||
bicenter(n)
|
||
print(n‘: ’unrooted[n])
|