题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1027
题目大意:求1-N的数列的第M个有序全排列
关键思想:用STL的next_permutation函数。或者康托展开
代码如下:
//STL全排列应用
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int n,m;
int a[1010];
while(cin>>n>>m){
for(int i=0;i<1010;i++)a[i]=i;
while(--m&&next_permutation(a+1, a+n+1));
for (int i = 1 ;i < n;i ++ ) cout << a[i] << " " ;
cout <<a[n]<< endl;
}
return 0;
}