对于每个 n n n,先输出 1 1 1,再倒序输出 2 2 2 到 n n n 即可。可以证明构造的排列只有 [ 1 ] [1] [1] 和 [ 1 , n , n − 1 , ⋯ , 3 , 2 ] [1,n,n-1,\cdots,3,2] [1,n,n−1,⋯,3,2] 共 2 2 2 个子集为排列。
代码:
#include<bits/stdc++.h>
using namespace std;
int t,n;
int main()
{
cin>>t;
while(t--)
{
cin>>n;
cout<<1<<' ';
for(int i=n;i>=2;i--)
cout<<i<<' ';
cout<<'\n';
}
return 0;
}