#P7822. 「RdOI R3」学习算法
「RdOI R3」学习算法
Description
There are days in the summer vacation. We assume MLE has enough time every day to study OI. MLE listed algorithms to choose from. Each day, MLE can only and must study exactly one algorithm.
Also, if MLE studies the same algorithm for a long time, they will get bored, so each algorithm cannot be studied for too many consecutive days. The -th algorithm can be studied for at most consecutive days. MLE does not need to study all algorithms.
MLE wants to know how many different study schedules there are to spend these days. Two schedules are different if and only if there exists at least one day on which the studied algorithm is different. Since the number of schedules may be very large, you only need to output the number of schedules modulo .
Input Format
The first line contains two integers .
The second line contains integers .
Output Format
Output one line with one integer: the number of schedules modulo .
3 2
1 2
4
2 1
1
0
8 5
4 2 3 4 2
356314
Hint
Sample Explanation
Sample #1
The first algorithm can be studied for at most one consecutive day, and the second one for at most two consecutive days. Therefore, there are four study schedules in total:
- .
- .
- .
- .
Sample #2
Since the only algorithm can be studied for at most one consecutive day, there is no valid schedule to spend days.
Constraints
This problem uses bundled testdata. Unless otherwise specified, the memory limit for each test point is 256MB.
For all data, , .
| subtask | score | special constraints | |
|---|---|---|---|
| none | |||
| memory limit is MB | |||
| none | |||
Translated by ChatGPT 5
京公网安备 11011102002149号