AA Tree

Time limit: 0.2s
Memory limit: 256MB
Input:
Output:

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 11.
  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 33, 55, 55, 1111 and 1111 nodes respectively. For clarity, right children on an equal level with their parent are shown in red.

Task

Given two numbers NN and LL, how many ways are there of arranging the values 11, 22, ..., NN in an AA tree such that it has exactly LL levels?

Input data

The only line of input will contain the integers NN and LL separated by a space.

Output data

Output the number of arrangements modulo 109+710^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.
  • 1L91 \leq L \leq 9
  • 1N10 0001 \leq N \leq 10 \ 000
# Points Constraints
0 0 Examples
1 19 L4L \leq 4
2 34 5L75 \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 22 and 33 above.

Example 2

stdin

442 6

stdout

896944318

Example 3

stdin

7133 9

stdout

980381648

Problem info

ID: 1834

Editors:

Author:

Source: RMI 2023: Day 1 Problem 1

Tags:

RMI 2023

Log in or sign up to be able to send submissions!