Sang-geun's Lock
Time limit1sMemory limit128 MB
Count the number of height-balanced binary trees with N nodes, print the last 9 digits padded to width 9.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Recursion, Combinatorics
- Solved
- No attempts yet
Problem
A certain lock uses a 9-digit number as its password. When you touch the lock, its LED display shows a single integer . The lock opens once you enter the last 9 digits of the number of trees that satisfy the condition below.
Consider binary trees with nodes. For every node, the difference between the heights of its left and right subtrees must be at most . The height of a subtree is the length of the longest path from that subtree's root down to a leaf. A subtree consisting of a single node has height , and an empty subtree (no nodes) has height .
Count how many distinct tree shapes there are.
Input
The input consists of several test cases. Each test case is a single integer with . Input continues until the end of the file.
Output
For each test case, print on its own line the last 9 digits of the number of trees corresponding to the given . If the value has fewer than 9 digits, pad it with leading zeros so that exactly 9 digits are printed.