#C5342. All Subsets Generation
All Subsets Generation
All Subsets Generation
Given a list of integers, generate all possible subsets (i.e., the power set) of the list. The solution set must not contain duplicate subsets. In other words, if the list contains duplicate elements, each subset should appear only once.
For clarity and consistency, the subsets must be output in non-decreasing order of their size, and for subsets of the same size, in lexicographical order. The empty subset is considered valid and should be output as an empty line.
The mathematical formulation of the power set is given by \[ \mathcal{P}(S) = \{ T : T \subseteq S \}\, \]
inputFormat
The first line contains an integer n
representing the number of elements in the list. The second line contains n
space-separated integers. If n = 0
, the second line is empty.
outputFormat
Output all unique subsets of the given list, one subset per line. Each subset should list its elements separated by a single space. For the empty subset, output an empty line. The subsets must be sorted first by their size (increasing order) and then lexicographically.## sample
1
7
7
</p>