#C1087. Generate All Subsets
Generate All Subsets
Generate All Subsets
You are given a list of n integers. Your task is to generate all possible subsets of this list. A subset can contain any number of elements (including zero), and the total number of subsets is given by the formula \(2^n\).
The subsets should be generated in the order in which they are produced by an iterative algorithm. For example, if the input list is [1, 2, 3], the output should be:
1 2 1 2 3 1 3 2 3 1 2 3
Note that the first line corresponds to the empty subset.
inputFormat
The first line contains a single integer n, representing the number of elements in the list. The second line contains n space-separated integers.
Example:
3 1 2 3
outputFormat
Print each subset on a new line. For each subset, print the elements (if any) separated by a single space. For the empty subset, print an empty line. The order of the subsets should follow the order of generation as described in the problem.
## sample3
1 2 3
1
2
1 2
3
1 3
2 3
1 2 3
</p>