CF1761F1.Anti-median (Easy Version)
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is the easy version of the problem. The only difference between the two versions is the constraint on n . You can make hacks only if all versions of the problem are solved.
Let's call an array a of odd length 2m+1 (with m≥1 ) bad, if element am+1 is equal to the median of this array. In other words, the array is bad if, after sorting it, the element at m+1 -st position remains the same.
Let's call a permutation p of integers from 1 to n anti-median, if every its subarray of odd length ≥3 is not bad.
You are already given values of some elements of the permutation. Find the number of ways to set unknown values to obtain an anti-median permutation. As this number can be very large, find it modulo 109+7 .
输入格式
The first line contains a single integer t ( 1≤t≤104 ) — the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer n (2≤n≤1000) — the length of the permutation.
The second line of each test case contains n integers p1,p2,…,pn ( 1≤pi≤n , or pi=−1 ) — the elements of the permutation. If pi=−1 , it's given, else it's unknown. It's guaranteed that if for some i=j holds pi=−1,pj=−1 , then pi=pj .
It is guaranteed that the sum of n2 over all test cases does not exceed 106 .
输出格式
For each test case, output a single integer — the number of ways to set unknown values to obtain an anti-median permutation, modulo 109+7 .
输入输出样例
输入#1
5 2 -1 -1 3 -1 -1 -1 4 1 2 3 4 6 -1 -1 3 4 -1 -1 8 -1 -1 -1 -1 -1 -1 -1 -1
输出#1
2 4 0 1 316
说明/提示
In the first test case, both [1,2] and [2,1] are anti-median.
In the second test case, permutations [1,3,2],[2,1,3],[2,3,1],[3,1,2] are anti-median. The remaining two permutations, [1,2,3] , [3,2,1] , are bad arrays on their own, as their median, 2 , is in their middle.
In the third test case, [1,2,3,4] isn't anti-median, as it contains bad subarray [1,2,3] .
In the fourth test case, the only anti-median array you can get is [5,6,3,4,1,2] .