0126. Combinations-2

Input file name: combo2.in
Output file name: combo2.ovt
Time limit: 500 ms
Memory limit: 64 megabytes

A combination of k elements out of n is an increasing sequence of k integer numbers in range from 1 to n.

Generate all combinations of k elements out of n in any order such that any two adjacent combinations have no more than one difference (that is, if S1 and S2 are two adjacent combinations, then #(S1 - S2) ≤ 1).

Input file

Input file contains two integer numbers n and k such that 1 ≤ k ≤ n ≤ 15.

Output file

Output Cnk lines – all combinations of k elements out of n in any order satisfying the conditions above.

Examples:

combo2.incombo2.ovt
3 21 2 1 3 2 3


Source: Petrozavodsk Summer 2003. Blitz Kontest, Monday, August 25
Author: Andrew Lopatin, Nick Durov

Discuss       Submit a solution



Printable version