#P7822. 「RdOI R3」学习算法

「RdOI R3」学习算法

Description

There are nn days in the summer vacation. We assume MLE has enough time every day to study OI. MLE listed mm 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 ii-th algorithm can be studied for at most aia_i consecutive days. MLE does not need to study all algorithms.

MLE wants to know how many different study schedules there are to spend these nn 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 109+710^9+7.

Input Format

The first line contains two integers n,mn,m.
The second line contains mm integers a1,a2,,ama_1,a_2,\cdots,a_m.

Output Format

Output one line with one integer: the number of schedules modulo 109+710^9+7.

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:

  • 1,2,21,2,2.
  • 2,1,22,1,2.
  • 2,2,12,2,1.
  • 1,2,11,2,1.

Sample #2

Since the only algorithm can be studied for at most one consecutive day, there is no valid schedule to spend 22 days.


Constraints

This problem uses bundled testdata. Unless otherwise specified, the memory limit for each test point is 256MB.

For all data, 1ain7×1031\le a_i \le n\le 7 \times 10^3, 1m7×1031\le m \le 7\times 10^3.

subtask score n,mn,m\le special constraints
11 55 none
22 1010 100100
33 1515 500500
44 2020 7×1037\times 10^3 ai=1a_i=1
55 memory limit is 500500 MB
66 3030 none

Translated by ChatGPT 5