#P12223. Counting Non-Symmetric Binary Trees
Counting Non-Symmetric Binary Trees
Counting Non-Symmetric Binary Trees
In this problem, you are given two integers (n) and (k). Consider all distinct binary trees with exactly (n) nodes (unlabeled, i.e. only shape matters). Each node (i) in the tree has a left child (l_i) and a right child (r_i) (if a child is missing, its subtree is considered to have height 0). Let (h_x) denote the height of the subtree rooted at node (x) (with (h_x = 0) for a non-existent node and (h_x = 1) for a leaf).
A binary tree is defined as a non-symmetric binary tree if for every node (i) the following condition holds:
[ \max{h_{l_i}, h_{r_i}} \ge k \times \min{h_{l_i}, h_{r_i}}. ]
Note that if one of the children is missing (i.e. its height is 0) and the other exists, then the condition automatically holds since (\max) will be positive and (\min) is 0. Your task is to calculate the number of distinct non-symmetric binary trees with exactly (n) nodes.
Input Format: Two integers (n) and (k) are given in one line, separated by a space.
Output Format: Output a single integer representing the number of non-symmetric binary trees with (n) nodes.
Note: The answer might be large; however, no modulo operation is required.
inputFormat
The input consists of a single line containing two integers \(n\) and \(k\), separated by a space.
For example:
3 2
outputFormat
Output a single integer — the number of non-symmetric binary trees with \(n\) nodes.
For example:
2
sample
1 2
1