#C6617. Generate All Permutations
Generate All Permutations
Generate All Permutations
You are given a list of n unique integers. Your task is to generate and print all possible permutations of the given list. Each permutation should be printed on a new line with its integers separated by spaces.
The solution should use a backtracking method to generate the permutations. There is no requirement on the order of the permutations; the order produced by your backtracking implementation is acceptable.
Input Format (from stdin):
- The first line contains an integer n, the number of integers.
- The second line contains n space-separated integers.
Output Format (to stdout):
- Print each permutation on a separate line. Within each line, print the integers of the permutation separated by a single space.
Example:
Input:
3
1 2 3
Output:
1 2 3
1 3 2
2 1 3
2 3 1
3 2 1
3 1 2
inputFormat
The input will be read from stdin and consists of two lines. The first line contains an integer n (\(1 \leq n \leq 10\)). The second line contains n distinct integers separated by a single space.
outputFormat
The output should list all generated permutations. Each permutation must be printed in one line with the numbers separated by a space. The order of the permutations depends on your backtracking approach.
## sample1
1
1
</p>