Permutation
Time limit3sMemory limit256 MB
Count the ways to fill the unknown positions of a partial permutation so the result has an arithmetic progression subsequence of length 3 or more, modulo 10^9+7.
- Level
Hard8 of 10
- Topics
- Combinatorics, Dynamic programming, Math
- Solved
- No attempts yet
Problem
Chiaki has a permutation of the integers , but some of its positions are unknown. She wants to know how many ways there are to fill the unknown positions so that the resulting permutation contains a subsequence of length at least that is an arithmetic progression.
Since the number may be very large, print it modulo .
Input
The first line contains , the number of test cases. Each test case has two lines.
The first line contains (), the length of the permutation.
The second line contains integers (). means that position is unknown. All nonzero values are distinct.
The sum of over all test cases does not exceed .
Output
For each test case, print the answer on its own line.