### 1996 Canadian Computing Competition, Stage 1

## Problem C: Pattern Generator

Write a program that repeatedly reads two numbers `n` and
`k` and prints all bit patterns of length `n` with
`k` ones in descending order (when the bit patterns are
considered as binary numbers). You may assume that 30 ≥
`n` > 0, 8 > `k` ≥ 0, and `n`
≥ `k`. The first number in the input gives the number of
pairs `n` and `k`. The numbers `n` and
`k` are separated by a single space. Leading zeroes in a bit
pattern should be included. See the example below.

### Sample Input

3 2 1 2 0 4 2

### Sample Output

The bit patterns are 10 01 The bit patterns are 00 The bit patterns are 1100 1010 1001 0110 0101 0011

All Submissions

Best Solutions

**Point Value:** 10

**Time Limit:** 10.00s

**Memory Limit:** 16M

**Added:** Sep 28, 2008

**Problem Types:**[Show]

**Languages Allowed:**

C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

## Comments (Search)

magmascorpion919on Oct 22, 2016 - 1:17:57 am UTC QuestionOnly asking because it says in problem type "recursion" and a comment says you need to use recursion

Kiritoon Oct 22, 2016 - 4:30:55 pm UTC Re: Questionwhcdavidcaon Oct 29, 2015 - 1:27:08 am UTC Questionjargonon Oct 29, 2015 - 6:16:35 am UTC Re: Questionwhcdavidcaon Oct 29, 2015 - 3:40:25 pm UTC Re: Questionjargonon Oct 29, 2015 - 4:39:52 pm UTC Re: QuestionEdit: However, after looking a bit more, it's not your only problem. Try some more test cases.

whcdavidcaon Oct 29, 2015 - 7:45:11 pm UTC Re: QuestionLOLWHATOMGBBQon Aug 08, 2014 - 12:57:20 am UTC Am i doing something wrongawaykenedon Aug 08, 2014 - 1:21:39 am UTC Re: Am i doing something wronglol

//made the same mistake

also your algorithm does not print the patterns in the order specifieddsdss

"Write a program that prints all bit patterns of length n with k ones in descending order "

LOLWHATOMGBBQon Aug 08, 2014 - 1:27:03 am UTC Re: Am i doing something wronghelios26on Nov 07, 2011 - 1:29:34 am UTC Any help?~helios26

bbi5291on Nov 07, 2011 - 1:53:52 am UTC Re: Any help?helios26on Nov 08, 2011 - 1:15:23 am UTC Re: Re: Any help?Thanks,

~helios26

SourSpinachon Nov 08, 2011 - 5:00:48 am UTC Re: Re: Any help?zhxl0903on Jan 08, 2009 - 1:18:30 am UTC conditions?hansonw1on Jan 08, 2009 - 1:25:09 am UTC Re: conditions?zhxl0903on Jan 08, 2009 - 1:29:41 am UTC Re: Re: conditions?dAedaLon Jan 08, 2009 - 1:39:56 am UTC Re: Re: Re: conditions?Maybe read the problem statement more carefully next time.