#T258. 组合的输出
组合的输出
Description
Permutations and combinations are commonly used mathematical methods. A combination refers to selecting r elements from n elements (without considering order and with r ≤ n). We can simply understand the n elements as natural numbers 1, 2, ..., n, and choose any r numbers from them.
You are now required to output all combinations using a recursive method.
For example, when n = 5 and r = 3, all combinations are:
1 2 3 1 2 4 1 2 5 1 3 4 1 3 5 1 4 5 2 3 4 2 3 5 2 4 5 3 4 5
Input Format
A single line containing two natural numbers, n and r (1 < n < 21, 1 ≤ r ≤ n).
Output Format
All combinations, with each combination occupying a separate line and the elements within each combination arranged in ascending order. Each element should occupy exactly three character positions. All combinations should also be listed in lexicographical order.
5 3
1 2 3
1 2 4
1 2 5
1 3 4
1 3 5
1 4 5
2 3 4
2 3 5
2 4 5
3 4 5