CF1896A Jagged Swaps
题目描述
你有一个$1\sim n$的全排列数组$a$,你可以做如下操作。
- 选择一个$2$到$n-1$的满足$a_{i-1}a_{i+1}$的下标$i$,交换$a_i$与$a_{i+1}$。
判断你能否通过如下操作对$a$从小到大排序。
输入格式
第一行数据组数$t(1\le t \le 5000)$。
每组数据第一行为$n(3\le n \le 10)$,第二行为$a_1,a_2,\cdots,a_n$。
输出格式
对每组数据,如可以排序输出`YES`,否则输出`NO`。
说明/提示
In the first test case, the permutation is already sorted.
In the second test case, we can choose index $ i=2 $ as $ 12 $ to form $ [1, 2, 3, 5, 4] $ . Then, we can choose index $ i=4 $ as $ 34 $ to form $ [1, 2, 3, 4, 5] $ .
In the third test case, it can be proven that it is impossible to sort the permutation.