P27392 [AtCoder] Stacked Books
提高-
题目描述

Problem Description

$ N $ books are stacked in a single row. The thickness of the book on the $ i $th level from the bottom ($1 \leq i \leq N$) is $ h_i $.

You are trying to remove the books one by one. If the highest point of a book is at most $ H $, you can remove that book regardless of its position in the stack. When a book is removed, the books above it will slide down.

Find the total number of possible sequences in which you can remove all the books.

Input Format

The input is given from the standard input in the following format:

$ N $ $ H $ $ h_1 $ : $ h_N $

Output Format

Output the total number of possible sequences in which you can remove all the books.

Sample Input and Output

Sample Input #1

4 3
2
1
2
3

Sample Output #1

3

Sample Input #2

10 100
19
2
1
2
18
4
9
4
24
19

Sample Output #2

3225600

Notes/Hints

Constraints

  • $1 \leq N \leq 10$
  • $1 \leq H \leq 100$
  • $1 \leq h_i \leq H$
  • All values given in the input are integers.

Sample Explanation 1

There are $ 3 $ possible sequences:
- Remove the books in the order from the 1st level, 2nd level, 3rd level, and 4th level from the bottom.
- Remove the books in the order from the 1st level, 3rd level, 2nd level, and 4th level from the bottom.
- Remove the books in the order from the 2nd level, 1st level, 3rd level, and 4th level from the bottom.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 3 2 1 2 3
样例输出
3