solution - AT_arc182_b
Solution
我们可以想到对于
设
设对
所以
显然,每个数在进行好多次转移最后都会变成
这里可以对逆转移打个表找规律,但我们注意力惊人可以发现,逆转移不就是一个完全二叉树上的一个节点和转移到它的两个子节点吗?!又因为限制
于是问题就转化成了,在深度为
bfs 贪心即可,这一部分就不作详细解释了。
Code
#include<iostream>
#include<cstdio>
#include<set>
#include<vector>
#include<queue>
#define int long long
#define il inline
#define pb emplace_back
using namespace std;
const int MAXN=2e5+5;
int n,k;
int cnt=0;
vector <int> ans;
struct qwq{int v,dep;};
queue <qwq> q;
il void bfs()
{
q.push((qwq){1,0});
int cnt=1;
qwq ck;
while(!q.empty())
{
ck=q.front(); q.pop();
if(ck.dep==k-1)
{
ans.pb(ck.v);
continue;
}
q.push((qwq){ck.v<<1,ck.dep+1});
if(cnt<n) q.push((qwq){ck.v<<1|1,ck.dep+1}),++cnt;
}
for(int i=cnt;i<n;++i) ans.pb((1<<k)-1);
}
il void solve()
{
cin>>n>>k;
vector<int>().swap(ans);
queue<qwq>().swap(q);
bfs();
for(int i:ans) cout<<i<<' ';
cout<<'\n';
}
signed main()
{
ios::sync_with_stdio(0);
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
cout.tie(nullptr);
int T;
cin>>T;
while(T--)
solve();
return 0;
}