UTS Open '21 P3 - Latin Class

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 1.0s
Memory limit: 128M

Author:
Problem type

The school year has just started, and Edward has found out why Allen isn't in class sometimes. This year, he finally has Latin class with Allen and wants to sit next to him. In the classroom, there are N students seated in a line, the ith student from the left having height hi. At the start of every day, Mr. Carswell will partition all N students into any number of contiguous non-empty groups. However, being the naughty student he is, Allen will only show up to class if the maximum height of each group forms a non-descending sequence.

Please help Edward find the number of partitions of students that satisfy the given condition modulo 109+7.

Constraints

For this problem, you will NOT be required to pass the sample cases in order to receive points. In addition, all subtasks are disjoint, and you are NOT required to pass previous subtasks to earn points for a specific subtask.

For all subtasks:

1N105

1hi109

Subtask 1 [15%]

1N21

Subtask 2 [25%]

1hi100

Subtask 3 [60%]

No additional constraints.

Input Specification

The first line contains an integer N, the number of students.

The next line contains N integers hi (1iN), the heights of the students.

Output Specification

Output one integer, the number of partitions that satisfy the given condition modulo 109+7.

Sample Input 1

Copy
3
2 1 2

Sample Output 1

Copy
3

Explanation for Sample 1

The three valid partitions (each represented by a set of ranges) are: {[1,1],[2,3]},{[1,2],[3,3]},{[1,3]}.

Note that the partition {[1,1],[2,2],[3,3]} is invalid since the sequence formed by the maximum height in each group is not non-descending.

Sample Input 2

Copy
5
1 3 7 4 7

Sample Output 2

Copy
12

Comments

There are no comments at the moment.