HDU1027 (全排列)
题意:求N个数全排列,顺着数第M个
调用函数即可快速搞定。
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <iostream> 5 using namespace std; 6 const int maxn = 1002; 7 int num[ maxn ]; 8 int main(){ 9 int n,m; 10 while( scanf("%d%d",&n,&m)!=EOF ){ 11 memset(num,0,sizeof(num)); 12 for(int i=0;i<n;i++) 13 num[i]=i+1; 14 m--; 15 while(m--){ 16 next_permutation(num,num+n); 17 } 18 for(int i=0;i<n-1;i++) 19 printf("%d ",num[i]); 20 printf("%d\n",num[n-1]); 21 } 22 return 0; 23 }
keep moving...