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.
Input
3 1
Output
(2, 3, 1) (3, 1, 2)
Input
3 2
Output
(2, 1, 3) (1, 3, 2) (3, 2, 1)
Input
3 3
Output
(1, 2, 3)