#P1157. 组合的输出

组合的输出

Description

Permutation and combination are common mathematical methods. A combination means selecting rr elements from nn elements (order does not matter and rnr \le n). We can simply think of the nn elements as the natural numbers 1,2,,n1, 2, \dots, n, and choose any rr numbers from them.

You are required to output all combinations.

For example, when n=5,r=3n=5, r=3, all combinations are:

123,124,125,134,135,145,234,235,245,345123,124,125,134,135,145,234,235,245,345.

Input Format

A single line with two natural numbers n,rn, r (1<n<211 < n < 21, 0rn0 \le r \le n).

Output Format

Output all combinations. Each combination occupies one line, and the elements in it are sorted in ascending order. Each element occupies a field width of three characters. All combinations are in lexicographical order.

Note: When outputting, each number must have a field width of 33. In C++, you can use the following code:

cout << setw(3) << x;

This outputs a number xx with a field width of 33. Note that you need the header file iomanip.

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

Hint

Translated by ChatGPT 5