#C13699. Subsets Generation
Subsets Generation
Subsets Generation
Given a list of distinct integers, you are to generate all possible subsets in non‐descending order. There are two modes for this problem:
-
Mode 1: Generate all subsets. These subsets must be sorted first by their length and then in lexicographical order.
-
Mode 2: Generate only the subsets that have exactly elements. The subsets should be output in non‐descending order as well.
Note: In both modes, the input list of integers should be sorted in non‐descending order before processing. The mathematical formulation for a subset is such that if then . This ordering is maintained in the output.
inputFormat
Input is read from standard input (stdin) and its format depends on the mode:
-
The first line contains a single integer indicating the mode. If the mode is 1, then the problem requires generating all subsets. If the mode is 2, then the problem requires generating only those subsets of length .
-
For mode 1:
- The second line contains an integer , the number of elements in the list.
- The third line contains space-separated integers.
-
For mode 2:
- The second line contains an integer , the number of elements in the list.
- The third line contains space-separated integers.
- The fourth line contains the integer indicating the desired length of each subset.
outputFormat
The output should be printed to standard output (stdout) as a single line string representing a Python-style list of lists.
- For mode 1, print the list of all subsets sorted by length and lexicographically.
- For mode 2, print the list of all subsets that have exactly elements.
Each subset is printed in the format [a, b, ...].## sample
1
3
1 2 3
[[], [1], [2], [3], [1, 2], [1, 3], [2, 3], [1, 2, 3]]