#P9906. [COCI 2023/2024 #1] Kocke

[COCI 2023/2024 #1] Kocke

Problem Description

On Donald’s 13th birthday, his father gave him a set of LEGO bricks. In this set, there are nn bricks of the same size, and the color of the ii-th brick is ii. He wants to use these bricks to build a wall.

Donald will build his wall on a base where the LEGO bricks are arranged in a line. The base has kk positions where bricks can be placed. He places the bricks in the following way:

  • First, he places the brick of color 11 on any position on the base.
  • For each brick of color 22 to nn, he always chooses a position adjacent to the previous brick, and places this brick on the top of the stack at that position.

He represents the wall with a sequence of length kk: for position ii, if there is no brick in that position, it is 00; otherwise, it is the color of the topmost brick at that position.

How many different sequences are there? Output the answer modulo 109+710^9+7.

Input Format

One line with two integers n,kn, k, representing the number of bricks and the number of positions.

Output Format

One integer, the answer modulo 109+710^9+7.

4 3
8
3 5
14
100 200
410783331

Hint

Sample Explanation #1

The possible sequences are: $(0, 3, 4), (2, 3, 4), (0, 4, 3), (1, 4, 3), (4, 3, 0), (4, 3, 2), (3, 4, 0), (3, 4, 1)$.

Sample Explanation #2

One possible sequence is (0,3,2,0,0)(0,3,2,0,0). The operations are:

  • Place the brick numbered 11 on the top of position 22.
  • Place the brick numbered 22 on the top of position 33.
  • Place the brick numbered 33 on the top of position 22.

Constraints

For 100%100\% of the testdata, 2n,k50002 \leq n, k \leq 5000.

This problem uses bundled testcases.

Subtask Special Property Score
11 n,k18n, k \leq 18 2020
22 n,k50n, k \leq 50 3030
33 n,k500n, k \leq 500
44 No special property

Notes

The scoring of this problem follows the original COCI problem, with a full score of 110110.

Translated from COCI2023-2024 CONTEST #1 T4 Kocke.

Translated by ChatGPT 5