Longest Increasing Subsequence
题意: 构造一个1,2,…,n 的排列,使其 恰好有 m 个不同的最长上升子序列。
#include<bits/stdc++.h>
using namespace std;
#define int long long
#pragma GCC optimize(3)
#define re register int
typedef pair<int,int>PII;
#define pb push_back
#define mb pop_back
#define debug(a) cout<<a<<' ';
#define fer(i,a,b) for(re i=a;i<=b;i++)
#define der(i,a,b) for(re i=a;i>=b;i--)
const int N = 110;
int a[N];
void cf(){
int n;
cin>>n;
int bit = 0;
int nn=n;
while(nn){
bit++;
nn>>=1;
}
int need=bit-1;
int st=need*2+1;
nn=n;
int sum=0;
for(int i=need-1;i>=0;i--){
if((nn>>i)&1){
a[i]=need-i-sum;
sum+=a[i];
}
else a[i]=0;
}
cout<<sum+st<<endl;
for(int i=0;i<need;i++){
for(int j=1;j<=a[i];j++)cout<<st<<' ',st++;
cout<<(i+1)*2<<' '<<(i+1)*2-1<<' ';
}
cout<<st<<endl;
}
signed main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int _=1;
cin>>_;
while(_--){
cf();
}
return 0;
}