Sample Input
6 4 //输出第4个全排列
11 8
Sample Output
1 2 3 5 6 4
1 2 3 4 5 6 7 9 8 11 10
1 # include <cstdio> 2 # include <iostream> 3 # include <algorithm> 4 using namespace std ; 5 6 int a[2000] ; 7 8 int main () 9 { 10 int n , m ; 11 while (scanf("%d %d" , &n , &m) != EOF) 12 { 13 int i ; 14 for (i = 1 ; i <= n ;i++) 15 a[i] = i ; 16 int num = 1 ; 17 while (num < m) 18 { 19 next_permutation(a+1 , a+1+n) ; 20 num++ ; 21 } 22 for (i = 1 ; i <= n-1 ;i++) 23 printf("%d " , a[i]) ; 24 printf("%d\n",a[n]) ; 25 } 26 }
时间: 2024-10-11 17:43:17