A complete k-ary tree is a k-ary tree in which all leaves have same depth and all internal nodes have degree or (equivalently) branching factor k. It is easy to determine the number of nodes of such a tree.
Given the depth and branching factor of such a tree, you must determine in how many different ways you can number the nodes of the tree so that the label of each node is less that that of its descendants. This is the property which defines the binary heap priority queue data structure for k = 2. In numbering a tree with N nodes, assume you have the labels (1, 2, 3,…, N – 1, N) available.
The input file will contain several lines of input. Each line will contain two integers k and d. Here k > 0 is the branching factor of the complete k-ary tree and d > 0 is the depth of the complete k-ary tree. Your program must work for all pairs such that k x d <= 21.
For each line of input, produce one line of output containing an integer counting the number of ways the k-ary tree can be labeled, maintaining the constraints described above.
2 2 10 1