## Welcome To SDIBT ACM-ICPC Online Judge

Problem 1058. -- Complete Tree labeling ## Complete Tree labeling

Time Limit: 1 Sec Memory Limit: 64 MB

Submit: 0 Solved: 0

[Submit][Status][Discuss]## Description

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.

## Input

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.

## Output

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.

## Sample Input

2 2
10 1

## Sample Output

80
3628800

## HINT

## Source

[Submit][Status][Discuss]

HOME
Back

한국어 中文 English

All Copyright Reserved 2008-2010 SDIBT TEAM

GPL2.0 2003-2010 HUSTOJ Project TEAM

Anything about the Problems, Please Contact Admin:admin