#P7132. 小 L 的零食
小 L 的零食
Description
optimization is automatically enabled when submitting.
Little L now wants to put some snacks into a box. However, if the snacks are not stacked steadily, they will fall and break, so Little L wants to find how many stable ways there are to stack snacks.
Each snack can be abstracted as a square, and the bottom of the box can be seen as a one-dimensional line segment of length . More precisely, the snacks are divided into piles, placed in the box from left to right, denoted as pile in order. We consider the height of pile to be the number of snacks in this pile, and any pile is allowed to contain no snacks.
We define pile to be stable if and only if:
- , i.e. the height of this pile does not exceed .
- While satisfying the previous condition, at least one (or both) of the following conditions holds:
- or . In this case, one side is the inner wall of the box, so this pile will not fall.
- . In this case, among the two neighboring piles, at least one is tall enough to support this pile so that it will not fall.
We define a stable way to stack snacks as a sequence of length such that, when stacking according to this sequence, every pile is stable.
Obviously, the box can hold at most snacks. We assume Little L has no fewer than snacks, and it is not necessary to put all snacks into the box. In addition, we assume every snack is exactly the same.
Input Format
There are lines in total.
The first line contains two positive integers .
The second line contains integers , with the meaning as shown in the red part in the Description.
The two numbers on each line are separated by a single space. The testdata is generated on Windows. There may be extra spaces at the end of a line.
Output Format
Print one integer per line, representing the number of stable ways to stack snacks, modulo .
3 3
3 1 1
59
10 13
12 13 1 4 5 9 7 0 3 8
851695394
Hint
This problem uses the following scoring strategy:
subtask (##):, ;
subtask (##):, ;
subtask (##):, ;
subtask (##):, .
For of the testdata: , . You must pass all test points within a subtask to be considered as passing that subtask.
This problem enables subtask dependencies.
Translated by ChatGPT 5
京公网安备 11011102002149号