Write a program to print all the permutations of with exactly cycles, where . For exemple, consider the permutation . At position there is a , at position there is a , and at position there is a . Therefore, one of the cycles is . The other two cycles are and . The permutation has the two cycles and , and the permutation only has the cycle .
Input consists of and , with .
Print all the permutations of with cycles.
You can print the solutions to this exercise in any order.
A possible program does not build the permutations consecutively from left to right, but jumping over the solution, using a function
void f(int i, int ini, int cells, int cycles);
where @i@ is the next cell to fill, @ini@ is where the current cycle—still to be closed—starts, @cells@ is the number of cells still free, and @cycles@ is the number of cycles yet to be created.
Author: Unknown
Translator: Salvador Roura
Generation: 2026-01-25T12:03:59.828Z
© Jutge.org, 2006–2026.
https://jutge.org