#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 bricks of the same size, and the color of the -th brick is . 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 positions where bricks can be placed. He places the bricks in the following way:
- First, he places the brick of color on any position on the base.
- For each brick of color to , 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 : for position , if there is no brick in that position, it is ; otherwise, it is the color of the topmost brick at that position.
How many different sequences are there? Output the answer modulo .
Input Format
One line with two integers , representing the number of bricks and the number of positions.
Output Format
One integer, the answer modulo .
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 . The operations are:
- Place the brick numbered on the top of position .
- Place the brick numbered on the top of position .
- Place the brick numbered on the top of position .
Constraints
For of the testdata, .
This problem uses bundled testcases.
| Subtask | Special Property | Score |
|---|---|---|
| No special property |
Notes
The scoring of this problem follows the original COCI problem, with a full score of .
Translated from COCI2023-2024 CONTEST #1 T4 Kocke.
Translated by ChatGPT 5