#P1077. [NOIP 2012 普及组] 摆花

[NOIP 2012 普及组] 摆花

Description

Xiaoming’s flower shop has just opened. To attract customers, he wants to place a row of mm pots of flowers at the entrance. Based on a survey, he listed the nn most popular types of flowers, numbered from 11 to nn. To showcase more types, it is required that for each type ii, no more than aia_i pots are used. When arranging, flowers of the same type must be placed together, and different types must be placed in increasing order of their labels.

Write a program to compute how many different arrangements there are.

Input Format

The first line contains two positive integers nn and mm, separated by a single space.

The second line contains nn integers, separated by single spaces, representing a1,a2,,ana_1, a_2, \cdots, a_n.

Output Format

Output a single integer, the number of arrangements. Note: since the number may be large, output the answer modulo 106+710^6 + 7.

2 4
3 2

2

Hint

Constraints

  • For 20%20\% of the testdata: 0<n80 < n \le 8, 0<m80 < m \le 8, 0ai80 \le a_i \le 8.
  • For 50%50\% of the testdata: 0<n200 < n \le 20, 0<m200 < m \le 20, 0ai200 \le a_i \le 20.
  • For 100%100\% of the testdata: 0<n1000 < n \le 100, 0<m1000 < m \le 100, 0ai1000 \le a_i \le 100.

NOIP 2012 Junior Problem 3.

Translated by ChatGPT 5