给定从1到n的整数,确定可以用这些数字构建多少个有效的二叉堆。
Example: 1 2 3 4
有效的最小堆包括:{1 2 3 4}
,{1 3 2 4}
,{1 2 4 3}
,
因此答案是3。
给定从1到n的整数,确定可以用这些数字构建多少个有效的二叉堆。
Example: 1 2 3 4
有效的最小堆包括:{1 2 3 4}
,{1 3 2 4}
,{1 2 4 3}
,
因此答案是3。
f(1) = 1 //no sons
f(2) = f(1) * 1 //one son and a root
//chose which element will go to the left sub-tree, and recursively invoke.
f(3) = Chose(2,1)* f(1) * f(1) * 1
f(4) = Chose(3,2)*f(2) * f(1) * 1 //chose which 2 elements will go to the left sub tree
...