AlienAndPermutation
SRM 605 · 2013-12-22 · by Witaliy
Problem Statement
Note that in this problem you are given a
Alien Fred wants to destroy the Earth. But before he does that, he wants to play with a permutation.
Fred has a permutation of all the integers between 1 and N, inclusive.
You are given a
Fred will now make a sequence of changes to P. Each change will look as follows: Fred will select a contiguous non-empty segment of P, and change all of its elements to the largest one among them. (Note that after such a change P will most likely stop being a permutation. This is allowed.)
You are also given an
Let X be the total number of different sequences he can produce at the end of the above process. Return the value (X modulo 1,000,000,007).
Constraints
- P will contain between 1 and 200 elements, inclusive.
- P will represent a permutation of integers between 1 and N, inclusive, where N is the number of elements in P.
- K will be between 0 and 200, inclusive.
{1, 2}
1
Returns: 2
The following two sequences are possible in this case: (1, 2) and (2, 2).
{3, 1, 2}
2
Returns: 4
Four sequences are possible in this case: (3, 1, 2) (3, 2, 2) (3, 3, 2) (3, 3, 3)
{4, 3, 2, 1}
2
Returns: 13
{1, 7, 2, 3, 6, 4, 5}
3
Returns: 77
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}
12
Returns: 379796836
Submissions are judged against all 77 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class AlienAndPermutation with a public method int getNumber(vector<int> P, int K) · 77 test cases · 2 s / 256 MB per case