[Solution] Count Partitions CodeChef Solution
Problem
An array of length consisting of only distinct elements is said to be good if the following condition holds:
- Let be the index of the maximum element of .
- Then, must be in ascending order, i.e, .
For example, and are good arrays, while and are not.
You are given a permutation of length . You have to partition into some non-empty good subarrays. Note that every element of should be contained in exactly one subarray.
Find the total number of valid partitions.
Since the answer can be quite large, please print it modulo .
Note: A permutation of length is an arrangement of the integers .
Input Format
- The first line of input contains a single integer denoting the number of test cases. The description of test cases follows.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer , the length of .
- The second line contains space-separated distinct integers .
Output Format
For each test case, output on a new line the number of valid partitions modulo .
No comments:
Post a Comment