#include <iostream>
#include <bits/stdc++.h>
using namespace std;
/*
6 4
11 8
1 2 3 5 6 4
1 2 3 4 5 6 7 9 8 11 10
*/
int main() {
int n,m;
while (cin >> n >> m)
{
vector<int> v;
for (int i = 1; i <= n; ++i) v.push_back(i);
for (int i = 0; i < m-1; ++i)
{
next_permutation(v.begin(), v.end());
}
for (int i = 0; i < n; ++i)
cout << v[i] << " ";
cout << endl;
}
return 0;
}
如果没学过next_permutation这道题可能很棘手,但只要学过这个按照字典序迭代的stl函数,就可以轻松解决,我在这里没考虑m>n 的情况 可以将next_permutation放到判断中去。然后我擦合约资料发现next_permuation也可用于普通数组,使用指针即可