"South of training" on the difficulty of the example is really small, barely able to understand the analysis, its thinking is really unexpected.
Although the topic is very strange, it will eventually be transformed into something that we are familiar with.
After the analysis of God in the book, it will eventually become:
A total of n leaves, the number f (n) of the tree with at least two child nodes per non-leaf node. Final output 2XF (n)
First, you can enumerate the number of leaves in the subtree of the root node, and for a subtree with I leaves, there is a total of f (i),
Set D (I, j) to indicate that each subtrees tree has a maximum of I leaf nodes and a total of J-leaf-node schemes.
The answer is D (n-1, N)
Suppose that there is a subtree of I leaves, because each subtree is independent of each other, so for a subtree of p with I leaves, there are C (f (i) +p-1, p) cases, the whole arrangement of repeating elements.
D (i, j) = Sum{c (f (i) +p-1, p) xd (i-1, J-PXI) | p >= 0 and PXi <= J}
Boundary:
D (i, 0) = d (i, 1) = 1 (i >= 1), D (0, 0) = 1
1#include <cstdio>2 3 Const intMAXN = -;4 Long Longd[ to][ to], f[ to];5 6 Long LongCLong LongNLong Longm)7 {8 Long LongAns =1;9 if(M > n-m) m = n-m;Ten for(inti =0; I < m; i++) One { AAns *= N-i; -Ans/= i+1; - } the returnans; - } - - intMain () + { -f[1] =1; + intn =MAXN; Ad[0][0] =1; at for(inti =1; I <= N; i++) d[i][0] = d[i][1] =1; - for(inti =1; I <= N; i++) - { - for(intj =2; J <= N; J + +) - { - for(intp =0; P * I <= J; p++) inD[I][J] + = C (f[i]+p-1, p) * d[i-1][j-p*i]; - } tof[i+1] = d[i][i+1]; + } - the while(SCANF ("%d", &n) = =1&&N) *printf"%lld\n", n = =1?1: f[n] *2); $ Panax Notoginseng return 0; -}code June
UVa 10253 (combined number recursion) Series-parallel Networks