Problem:

Enumeration of Subsets II

  You are given a set $T$, which is a subset of $U$. The set $U$ consists of $0, 1, ... n-1$.

  Print all sets, each of which is a subset of $U$ and includes $T$ as a subset.

  Note that we represent $0, 1, ... n-1$ as 00...0001, 00...0010, 00...0100, ..., 10...0000 in binary respectively and the integer representation of a subset is calculated by bitwise OR of existing elements. 

Input

  The input is given in the following format.

$n$
$k \; b_0 \; b_1 \; ... \; b_{k-1}$

$k$ is the number of elements in $T$, and $b_i$ represents elements in $T$.

Output

  Print the subsets ordered by their decimal integers. Print a subset in the following format.

$d$: $e_0$ $e_1$ ...

  Print ':' after the integer value $d$, then print elements $e_i$ in the subset in ascending order. Separate two adjacency elements by a space character.

Constraints

  
$1 \leq n \leq 18$

  
$0 \leq k \leq n$

  
$0 \leq b_i < n$

Sample Input 1

4
2 0 2

Sample Output 1

5: 0 2
7: 0 1 2
13: 0 2 3
15: 0 1 2 3



Sample input:
4
2 0 2


Sample output:
5: 0 2
7: 0 1 2
13: 0 2 3
15: 0 1 2 3

Submission status: Accepted

Solution code:
n = int(input())
k, *b = map(int, input().split())
t = sum(1<<i for i in b)
for i in range(1 << n):
    if i & t != t:
        continue
    rs = [str(i) + ":"]
    for j in range(n):
        if i & (1 << j) != 0:
           rs.append(j)
    print(*rs)

Submission status: Accepted

Solution code:
n = int(input())
d = list(map(int,input().split()))

for b in range(2**n):
    a = bin(b)[2:]
    a = a[::-1]
    ans = []
    for i in range(len(a)):
        if a[i] == "1":
            ans.append(i)
    ans.sort()
    flag = True
    for i in d[1:]:
        if i not in ans:
            flag = False
            break
    if flag:
        print(str(b)+":",*ans)

Submission status: Accepted

Solution code:
n = int(input())
_, *B = map(int, input().split())
B = set(B)
for x in range(2**n):
    if all([x&1<<s for s in B]):
        if x == 0:
            print('0:')
        else:
            bits = [i for i, b in enumerate(f'{x:b}'[::-1]) if b == '1']
            print(f'{x}: {" ".join(map(str, bits))}')

Submission status: Accepted

Solution code:
n = int(input())
k, *b = map(int, input().split())

m = 0
for i in b:
    m |= 1 << i
    
for i in range(2**n):
    if i & m != m:
        continue
    
    if i == 0:
        print("0:")
        continue
    else:
        print("{}: ".format(i), end="")
    l = []
    for j in range(n):
        if i & (1 << j) != 0:
            l.append(j)
    print(*l)

Submission status: Accepted

Solution code:
n = int(input())
k, *l = [int(x) for x in input().split()]

m = 0
for i in l:
    m |= 1<<i

for i in range( 2**n ):
    if i & m != m:
        continue

    if i == 0:
        print("{}:".format(i))
        continue
    else:
        print("{}: ".format(i), end="")
    l = []
    for j in range(n):
        if i & (1<<j) != 0:
            l.append(j)
    print(*l)

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    bit = int(input())
    k, *E = map(lambda x: int(x), input().split())
    m = sum(1 << e for e in E)

    if (0 == m):
        print(f"0:")
    for d in range(1, 1 << bit):
        if (d & m == m):
            print(f"{d}: ", end="")
            print(" ".join([str(elem) for elem in range(bit) if d & (1 << elem)]))

Submission status: Accepted

Solution code:
n=int(input())
temp0=input().split( )
k=int(temp0[0])
T=[int(s) for s in temp0[1:]]

m=2**n
for i in range(m):
    temp=[0 for i in range(n)]
    j=i
    count=0
    while j>0:
        if j%2==1:
            temp[count]=1
        j//=2
        count+=1
    flag=True
    for t in T:
        if temp[t]==0:
            flag=False
    if flag:
        temp2=[]
        for k in range(n):
            if temp[k]==1:
                temp2.append(k)
        print(i,end="")
        if i!=0:
            print(":",end=" " )
            print(*temp2)
        else:
            print(":")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Bitset II - Enumeration of Subsets II
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_11_B&lang=jp

"""
n = int(input())
_, *B = map(int, input().split())
B = set(B)
for x in range(2**n):
    if all([x&1<<s for s in B]):
        if x == 0:
            print('0:')
        else:
            bits = [i for i, b in enumerate(f'{x:b}'[::-1]) if b == '1']
            print(f'{x}: {" ".join(map(str, bits))}')

Submission status: Accepted

Solution code:
n = int(input())

k, *list_b = map(int, input().split())

t = 0

for i in list_b:
    t += 2 ** i


for d in range(2 ** n):
    # all(m)
    if (d & t) != t:
        continue

    d_bin = "{:b}".format(d)

    list_e = []

    for cnt, bit in enumerate(reversed(d_bin)):
        if bit == "1":
            list_e.append(cnt)

    if list_e:
        print(f"{d}: ", end="")
        print(*list_e)
    else:
        print(f"{d}:")

Submission status: Accepted

Solution code:
n = int(input())
a, *b = map(int,input().split())
mask = 0
for i in b:
    mask = mask | (1<<i)
for i in range(1<<n):
    ans = []
    _i = i
    cnt = 0
    if (i & mask) == mask:
        while i:
            if i&1:
                ans.append(cnt)
            cnt += 1
            i=i>>1
        print(f'{_i}:',end = '')
        if _i == 0:
            print()
        else:print("",*ans)

Submission status: Accepted

Solution code:
n=int(input())
U=[n-1-i for i in range(n)]
ind='0'+str(n)+'b'

t=list(map(int,input().split()))
T=t[1:]

for i in range(2**n):
    compare=[int(j) for j in format(i,ind)]
    disp=[U[j] for j in range(n) if compare[j]==1]
    disp.reverse()
    if sorted(list(set(T)&set(disp)))==T:
        print(i,end=":")
        if len(disp)!=0:
            print(" "+' '.join(map(str,disp)),end="")
        print()

Submission status: Accepted

Solution code:
n = int(input())
_, *B = [int(x) for x in input().split()]

T = 0
for b in B:
    T |= 1 << b

s = []

for i in range(1 << n):
    if (i & T) == T:
        s.append(f'{i}:')
        for j in range(n):
            if i & 1 << j:
                s.append(f' {j}')
        s.append('\n')

print(''.join(s), end='')

Submission status: Accepted

Solution code:
n = int(input())
k, *b_arr = map(int, input().split())
masks = [1 << x for x in range(n)]
b_mask = 0
for b in b_arr:
    b_mask += 1 << b

for i in range(1 << n):
    if i & b_mask != b_mask:
        continue
    sub = [idx for idx, mask in enumerate(masks) if i & mask != 0b00]
    print('{}: {}'.format(i, ' '.join(map(str, sub)))) if len(sub) != 0 else print(f'{i}:')

Submission status: Accepted

Solution code:
n = int(input())
nn = pow(2, n)

k = list(map(int, input().split()))
mask = k[1:k[0]+1]

if k[0] == 0:
    for i in range(nn):
        if i == 0:
            print("0:")
        else:
            bin_str = "0" + str(n) + "b"
            bin_i = format(i, bin_str)
            ilist = list(bin_i)
            tmplist = []
            for j, bini in enumerate(ilist):
                if bini == '1':
                    tmplist.append(n - j - 1)
            tmplist.sort()
            tmp_str = ' '.join(str(tmp) for tmp in tmplist)
            print(str(i) + ": " + tmp_str)

else:
    for i in range(nn):
        if i == 0:
            continue
        bin_str = "0" + str(n) + "b"
        bin_i = format(i, bin_str)
        ilist = list(bin_i)
        tmplist = []
        for j, bini in enumerate(ilist):
            if bini == '1':
                tmplist.append(n - j - 1)
        if len(set(mask) & set(tmplist)) == k[0]:
            tmplist.sort()
            tmp_str = ' '.join(str(tmp) for tmp in tmplist)
            print(str(i) + ": " + tmp_str)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# Bitset 2 - Enumeration of Subsets 2


def subset(n, mask):
    for i in range(2**n):
        if i & mask == mask:
            yield i, [v for v in range(n) if i & (1 << v) > 0]


def run():
    n = int(input())
    mask = 0 & 2**n
    for i in input().split()[1:]:
        mask |= 1 << int(i)

    for i, vs in subset(n, mask):
        print("{}:{}".format(i, "".join([" {}".format(v) for v in vs])))


if __name__ == '__main__':
    run()

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
write = sys.stdout.write
N = int(readline())
k, *B = map(int, readline().split())
M = sum(1 << b for b in B)
if M == 0:
    write("0:\n")
for i in range(1, 1 << N):
    if i & M == M:
        write("%d: %s\n" % (i, " ".join(str(j) for j in range(N) if i & (1 << j))))