P1157 Output of Combinations
Description
Permutation and combination are common mathematical methods. A combination means selecting $r$ elements from $n$ elements (order does not matter and $r \le n$). We can simply think of the $n$ elements as the natural numbers $1, 2, \dots, n$, and choose any $r$ numbers from them.
You are required to output all combinations.
For example, when $n=5, r=3$, all combinations are:
$123,124,125,134,135,145,234,235,245,345$.
Input Format
A single line with two natural numbers $n, r$ ($1 < n < 21$, $0 \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 $3$. In C++, you can use the following code:
```cpp
cout
Explanation/Hint
Translated by ChatGPT 5