Possible Number

View as PDF

Submit solution


Points: 15 (partial)
Time limit: 1.0s
Memory limit: 32M

Author:
Problem type
Allowed languages
Python

Problem Statement

Given a binary string of length n, and given that there are k ones in the string, please determine all possible integers that can be represented by the string.

Input Specification

The first line of the input gives the number of test cases, T, and then T test cases follow.

Each test case consists one line of two integers, n and k, separated by a space

Output Specification

For each test case, output one line containing Case #x: y, where x is the case number(starting from 1) and y is a list consisting of all possible integers in ascending order.

Constraints

1 \leq T \leq 100

1 \leq n \leq 16

0 \leq k \leq n

Sample Input

2
8 1
4 2

Sample Output

Case #1: [1, 2, 4, 8, 16, 32, 64, 128]
Case #2: [3, 5, 6, 9, 10, 12]

Explaination

Case #1:
    0 0 0 0 0 0 0 1 -> 1
    0 0 0 0 0 0 1 0 -> 2
    0 0 0 0 0 1 0 0 -> 4
    0 0 0 0 1 0 0 0 -> 8
    0 0 0 1 0 0 0 0 -> 16
    0 0 1 0 0 0 0 0 -> 32
    0 1 0 0 0 0 0 0 -> 64
    1 0 0 0 0 0 0 0 -> 128
Case #2:
    0 0 1 1 -> 3
    0 1 0 1 -> 5
    1 0 0 1 -> 9
    0 1 1 0 -> 6
    1 0 1 0 -> 10
    1 1 0 0 -> 12

Hint

recursion for-loop combination


Comments

There are no comments at the moment.