#K95587. Unique Combinations

    ID: 38896 Type: Default 1000ms 256MiB

Unique Combinations

Unique Combinations

Problem Statement:

Given an integer \(n\), a list of \(n\) distinct items, and an integer \(r\), your task is to compute all unique combinations of \(r\) items chosen from the list. The result should be displayed in lexicographical order.

Details:

  • The items must first be sorted in lexicographical order.
  • Then, all combinations of size \(r\) are generated such that within each combination, the items appear in the sorted order.
  • The total number of combinations is given by the binomial coefficient \(\binom{n}{r}\).

Input/Output: The input is read from stdin and the output is printed to stdout.

inputFormat

Input Format:

  1. The first line contains a single integer \(n\), the number of unique items.
  2. The second line contains a single integer \(r\), the number of items to select for each combination.
  3. The third line contains \(n\) space-separated strings representing the items.

outputFormat

Output Format:

Print each unique combination on a new line. In each combination, the items should be printed as space-separated strings.

## sample
4
2
vase book candle frame
book candle

book frame book vase candle frame candle vase frame vase

</p>