QOJ.ac

QOJ

Time Limit: 0.25 s Memory Limit: 256 MB Total points: 100

#10141. AA Tree

统计

An AA tree is a binary search tree with a special structure. Every node has a value and a level. Values obey the usual binary search tree properties:

  1. The value of every left child (and every node in the subtree of the left child) is less than or equal to the value of its parent.
  2. The value of every right child (and every node in the subtree of the right child) is greater than or equal to the value of its parent.

Levels obey the following rules:

  1. The level of every leaf node is $1$.
  2. The level of every left child is exactly one less than that of its parent.
  3. The level of every right child is equal to or one less than that of its parent.
  4. The level of every right grandchild is strictly less than that of its grandparent.
  5. Every node of level greater than one has two children.

Below are five examples of AA trees, having $3$, $5$, $5$, $11$ and $11$ nodes respectively. For clarity, right children on an equal level with their parent are shown in red.

problem_10141_1.png

Task

Given two numbers $N$ and $L$, how many ways are there of arranging the values $1$, $2$, ..., $N$ in an AA tree such that it has exactly $L$ levels?

Input data

The only line of input will contain the integers $N$ and $L$ separated by a space.

Output data

Output the number of arrangements modulo $10^9 + 7$.

Constraints and clarifications

  • The problem statement is slightly modified due to an error in the definition of what a binary search tree is in the original statement.
  • $1 \leq L \leq 9$
  • $1 \leq N \leq 10 \ 000$
# Points Constraints
0 0 Examples
1 19 $L \leq 4$
2 34 $5 \leq L \leq 7$
3 47 No additional constraints

Example 1

stdin

5 2

stdout

2

Explanation

The two possible arrangements are shown in images $2$ and $3$ above.

Example 2

stdin

442 6

stdout

896944318

Example 3

stdin

7133 9

stdout

980381648
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.