T
T
tumur42021-12-09 04:31:37
Python
tumur4, 2021-12-09 04:31:37

How to generate placement by its number in lexicographic order?

We have: n = number of emails in permutation, K = number of emails in layout, and m = placement number. m placement number from N to M

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hint000, 2021-12-09
@tumur4

1. Organize the list of N elements in ascending order;
2. We will generate recursively (this is for simplicity of explanation, after mastering the idea, you can get by with a cycle);
2.1. If M==0, then exit from the recursion;
2.2. The first placement element is the element in the Lth position in the list, where L=((N*m-1)\A(N,M))+1 (numbering from one for clarity only); A(N,M)= number of placements from N to M; remove the selected element from the list;
2.3. For the next recursion step, we take m=m-(L-1)*A(N,M)/N; N=N-1; M=M-1;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question