This question, looked for a long time, did not find what the law, Baidu after, only know is the number of the smallest permutation is the first of the enumeration.
What a long knowledge!! ~
Knowing this rule, you can quickly write, algorithm this header file in another enumeration of the function next_permutation, the smallest permutation of the first, is called Next_permutation I-1 times after the arrangement . The same applies to next_permutation, which means that there are duplicate elements in the set.
The following is the code for AC:
#include <iostream> #include <algorithm>using namespace Std;int main () {int n, m, P[1005];while (CIN >> N >> m) {for (int i = 0; i < n; i++) P[i] = i + 1;m--;while (m--) {next_permutation (p, p + N);} for (int j = 0; J < N; j + +) J = = N-1? printf ("%d\n", P[j]): printf ("%d", P[j]);} return 0;}
Hangzhou Electric Acm1027--ignatius and the Princess II