#C4940. Topping Combinations
Topping Combinations
Topping Combinations
You are given a list of unique toppings represented as integers and an integer ( k ). Your task is to generate all possible combinations of exactly ( k ) toppings. Each combination must have its numbers in ascending order and the overall list of combinations should be sorted in lexicographical (increasing) order. This is a typical combinatorial generation problem that can be solved by backtracking or using combinatorial functions.
For example, if the toppings list is [1, 2, 3] and ( k = 2 ), the valid combinations are: [1, 2], [1, 3], and [2, 3].
inputFormat
Input is read from standard input (stdin). The first line contains two space-separated integers: ( n ) and ( k ), where ( n ) is the number of toppings and ( k ) is the size of each combination. If ( n > 0 ), the second line contains ( n ) space-separated integers representing the toppings.
outputFormat
Output the list of combinations to standard output (stdout). Each combination should be printed on a separate line with the numbers separated by a single space. In the case where ( k = 0 ), print an empty line representing the empty combination.## sample
3 2
1 2 3
1 2
1 3
2 3
</p>