Recursion 1 - Bit String Generator


Submit solution

Points: 5
Time limit: 1.0s
Memory limit: 256M

Author:
Problem types
Allowed languages
Java

Write a program that takes in two numbers \(N\) and \(K\) and prints all possible bit strings of length \(N\) with \(K\) ones in descending order.

Note: A bit string is a string containing only 0's and 1's

Constraints

\(1 \le N \le 28\)

\(0 \le K \le 7\)

\(K \le N\)

Input Specification

The first and only line of input consists of two space-separated integers \(N\) and \(K\), representing the length of the bit string and the number of ones respectively.

Output Specification

Output all possible bit string arrangements of length \(N\) with exactly \(K\) ones, each on a separate line. The bit strings should be output in descending order.

Sample Input 1

2 1

Sample Output 1

10
01

Sample Input 2

2 0

Sample Output 2

00

Sample Input 3

4 2

Sample Output 3

1100
1010
1001
0110
0101
0011

Comments

There are no comments at the moment.