Booming Business
Time limit2sMemory limit512 MB
Count ordered rooted trees with exactly w nodes and height exactly h, modulo 1e9+7, where children of each node are an ordered sequence.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Combinatorics, Tree, Recursion
- Solved
- No attempts yet
Problem
Bonsai is the art of growing small trees in small containers. You are an expert at it, and every year you win the Bonsai Association's pruning competition. You recently rented a small store to sell your creations, and now you need a window display that draws in customers. You want the most impressive tree that fits the window, but the window is only so tall and the floor of the display can only bear so much weight, so you need a tree of exactly the right height and weight.
By definition, a bonsai tree consists of a single branch with 0 or more smaller bonsai trees branching off from that branch.

Figure 1: four distinct bonsai trees.
The weight of a bonsai tree is the number of branches in it. The weights of the trees in Figure 1 are 1, 4, 6 and 6. The height of a bonsai tree is the length of the longest chain of branches from the root to the top. The heights of the trees in Figure 1 are 1, 2, 3 and 3.
The smaller trees branching off one branch are ordered from left to right. Two bonsai trees count as the same tree only when every branch carries the same smaller trees in the same order.
Given and , count the bonsai trees whose height is exactly and whose weight is exactly . The count can be very large, so print it modulo .
Input
One line with two integers and separated by a space ().
Output
Print one line with the number of bonsai trees of height and weight , modulo .