0126. Combinations-2

Имя входного файла: combo2.in
Имя выходного файла: combo2.ovt
Ограничение по времени: 500 ms
Ограничение по памяти: 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


Источник: Petrozavodsk Summer 2003. Blitz Kontest, Monday, August 25
Автор: Andrew Lopatin, Nick Durov

Обсудить       Отправить решение



Версия для печати