Problem:
 Score : 500 points    Problem Statement We have N locked treasure boxes, numbered 1 to N .  A shop sells M keys. The i -th key is sold for a_i yen (the currency of Japan), and it can unlock b_i of the boxes: Box c_{i1} , c_{i2} , ... , c_{i{b_i}} . Each key purchased can be used any number of times.  Find the minimum cost required to unlock all the treasure boxes. If it is impossible to unlock all of them, print -1 .      Constraints  All values in input are integers.  1 \leq N \leq 12  1 \leq M \leq 10^3  1 \leq a_i \leq 10^5  1 \leq b_i \leq N  1 \leq c_{i1} < c_{i2} < ... < c_{i{b_i}} \leq N         Input Input is given from Standard Input in the following format:  N  M  a_1  b_1  c_{11}  c_{12}  ...  c_{1{b_1}}  :  a_M  b_M  c_{M1}  c_{M2}  ...  c_{M{b_M}}       Output Print the minimum cost required to unlock all the treasure boxes.
If it is impossible to unlock all of them, print -1 .        Sample Input 1 2 3
10 1
1
15 1
2
30 2
1 2      Sample Output 1 25  We can unlock all the boxes by purchasing the first and second keys, at the cost of 25 yen, which is the minimum cost required.       Sample Input 2 12 1
100000 1
2      Sample Output 2 -1  We cannot unlock all the boxes.       Sample Input 3 4 6
67786 3
1 3 4
3497 1
2
44908 3
2 3 4
2156 3
2 3 4
26230 1
2
86918 1
3      Sample Output 3 69942

Solution (Python):
INF = 10 ** 10
n, m = map(int, input().split())
k = (1 << n) - 1
lst = [[INF for j in range(k+1)] for i in range(m+1)]
lst[0][0] = 0

for i in range(m):
    a, b = map(int, input().split())
    c = sum([1 << (x-1) for x in tuple(map(int, input().split()))])
    for j in range(k+1):
        if lst[i][j] != INF:
            lst[i+1][j | c] = min(lst[i+1][j | c], lst[i][j] + a)
            lst[i+1][j] = min(lst[i+1][j], lst[i][j])

print(lst[m][k] if lst[m][k] != INF else -1)

Solution (Python):
N, M = map(int, input().split())

inf = 10 ** 10

dp = [inf] * (1 << N)
dp[0] = 0



for _ in range(M):
    a, b = map(int, input().split())
    c = sum([2 ** (i - 1) for i in map(int, input().split())])
    
    

    for j in range(1 << N):
      dp[j | c] = min(dp[j] + a, dp[j | c])
      
res = dp[-1] if dp[-1] != inf else -1
print(res)

Solution (Python):
N, M = map(int, input().split())
V = []
INF = float("inf")
dp = [INF]*(1<<N)
dp[0] = 0
for i in range(M):
  a,b = map(int, input().split())
  c = list(map(int, input().split()))
  k = 0
  for j in range(b):
    k |= 1<<(c[j]-1)
  V.append((a,k))
  dp[k] = min(dp[k],a)

for i in range(1<<N):
  for a,k in V:
    dp[i|k] = min(dp[i|k],dp[i]+dp[k])  
print(dp[-1] if dp[-1] != INF else -1)

Solution (Python):
def main():
    n ,m = map(int, input().split(' '))
    inf = 10**9
    bit_dp = [inf for _ in range(2**(n))]
    bit_dp[0] = 0
    for i in range(m):
        a, b = map(int, input().split(' '))
        c = list(map(int, input().split(' ')))
        bit_n = 0
        for i in c:
            bit_n |= 1 << i-1
        for i in range(2**(n)):
            if bit_dp[i|bit_n] > bit_dp[i] + a:
                bit_dp[i|bit_n] = bit_dp[i] + a
    if bit_dp[-1] >= inf:
        print(-1)
    else:
        print(bit_dp[-1])
if __name__ == '__main__':
    main()

Solution (Python):
N, M = map(int, input().split())
V = []
INF = float("inf")
dp = [INF]*(1<<N)
dp[0] = 0
for i in range(M):
  a,b = map(int, input().split())
  c = list(map(int, input().split()))
  k = 0
  for j in range(b):
    k += 1<<(c[j]-1)
  V.append((a,k))
  dp[k] = min(dp[k],a)

for i in range(1<<N):
  for a,k in V:
    dp[i|k] = min(dp[i|k],dp[i]+dp[k])  
print(dp[-1] if dp[-1] != INF else -1)

Solution (Python):
def main():
    n ,m = map(int, input().split(' '))
    inf = 10**9
    bit_dp = [inf for _ in range(2**(n))]
    bit_dp[0] = 0
    for i in range(m):
        a, b = map(int, input().split(' '))
        c = list(map(int, input().split(' ')))
        bit_n = 0
        for i in c:
            bit_n |= 1 << i-1
        for i in range(2**(n)):
            bit_dp[i|bit_n] = min(bit_dp[i|bit_n], bit_dp[i] + a)
    if bit_dp[-1] >= inf:
        print(-1)
    else:
        print(bit_dp[-1])
if __name__ == '__main__':
    main()

Solution (Python):
import subprocess
import gzip, base64, os
import stat

gz = b'H4sIACd4j10C/+19C3hTVbb/SdJHeDUB0VseSsEgRaS0UEqLoi0QOJEUKi2IjnhI05RW26STnEDxCbZVYqgyjtfxzp0H/5k7/udxr+Od/4yDjgMFlOIbURkeooyDemJFig+sOpC71t77pPucnFNg9Lvf9/++idKd9TtrP9baa6/9Otn7brd3gdViEdSPVbhaQMoytpzQ5Qzf7E+xAFYqDIK/44SxQhbQmRxfuVCuCftY0mpoZ3w2+JcB/0qtlC61lmvCsYxPDS1cmCnwn3JN6LpR0ISCkJeKh2U9sJKiB1au0oS5GRQvzNbGs7J4fSxeH+NXQ8EqaEJVvgz2r4bhNUwuNZzP+OZz/Pipek+uw+8N1ZRuqC7XhJsY3yZdvOsgXpZw7h8nC5ey/Mz0ks/Kr4ZqPUxraqwtKZ7WVDe1qTEYbZ3aWloytaS4IBIqmE7K5GS8Cxcv0+gxl5V5JLMBfL5zyqU7C0atqH+hadhVR+PXHxrzwPet+Gw2i4dV0hF0NmSMH2S1CMXCekgan82Bf3Ph3+/emvHm4A2bpR/7//zcA83JPRs7/Be9Ub2lbdMN5SennpRuzslbU5jvftPb9eFlXSMfHTrvJ2Nbtq7z3PrkQPo5BgUYYYC/bjXGp1mM8d8JxrgzZWHazzgT/NVM43TuNMFfNMm304R/SZYxnm2C32yC35dhjDea5DvVJJ1SEz3/wQQfZZLODBN9rjZJp8UknU9M+C8z4V9iku/3Teol08R+akzyfdqEf5hJeVaZ8C834T9lYv/jTdJ5zKTenzLBnzZJ/y4T/TSa6HO2SfnHmeDrTPQ50oT/cRN5m03KL5qk85GJXGUm6bxtojfZBH/BpJwfm7S7SSZ62GeS/ism5awwkffPJvleCumMF0YLT9SyfpfhIxje61+l6Z8mZVJcqKP4CoYPyWA4S2c9w3/B8t07qlyT70Kmny2jtfgiyHc4pHOUpa/a2G0ZFBcCqzT93kELzXd9rZbfwfTZosu3KpOms6VWm84clv5RhjvZg4VMrlV1OrmY/sv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q3TVSTcVcrxs5NEnUaQFyaaUgzb9hcUWlZ56Ae+0qpr9Ptbycv4py4Ptndbz0gkx/JEokF1I5nOdVrPoSGN5SnFZMw3uUNVwFZed0IzS5dTQ9ee5uUwMVDXBVs7YMRUUC047x/ajatOkVpAxjN4qS6021UNrVpLrHA15Iq5cm7WpXfS3335uano3JNcrpVWp65XFabvjKjYR3t0qpC6L/sQuhtSmTO2ENBEi/MFpXogFvDF8ikd+GSdFIoC79omhdCcKBQFoBBrrOWRud3mOrS2CAK8v1jd70VnIj8067r9fQTRhdOm7QkgyuFNZzGdxSrTcMEE/1iGl3dKfbG7naOR3mLh3Xp18XCUkN0NOC8uhdwoZtDr0dG0J9i5ej6/0Wu4NYby3ay7310qVfi60XsTYS4SwidTN8WmWc03XR5eXcXcfpl1wbepG0G6/TE9HeCm6UCrYjsxSkFhAdxvnSrYF1zPOZ3m+vc73kSmitxv0G7vgb3P2ucweBUL3exFA8UndaqUj//o/dv67Lk/y8NM2szvn6c4OuehbfVRN9rTFzASZXyxvVMXc3vU4V5L1Bo0vl003pW7g83aCzNJCO9Xppzk9zYzk8Y1eHk8KVYFNoChh0ONzd8gajHno7vEEhwNYqJbC7W8GLwWTBwLxb1vXXfFFx+g3s+rFIY1Cgvu5/AFj8a6spjQAA'
bin = gzip.decompress(base64.b64decode(gz))
p = os.path.dirname(__file__)
pymain = os.path.join(p, "a.out")
with open(pymain, "wb") as f:
    f.write(bin)
os.chmod(pymain, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
if p == "":
    pymain = "./" + pymain
subprocess.call(pymain)



'''

n,m=[int(j) for j in input().split()]
dp=[10**18]*(2**(n))
dp[0]=0
cost=[]
for i in range(m):
    x,y=[int(j) for j in input().split()]
    tmp=set([int(j) for j in input().split()])
    ind=0
    for j in range(1,n+1):
        if j in tmp:
            ind|=2**(j-1)
    dp[ind]=x
    cost.append((ind,x))

for i in range(2**n):
    for j in range(m):
        dp[i|cost[j][0]]=min(dp[i|cost[j][0]],dp[i]+cost[j][1])

if dp[-1]!=10**18:
    print(dp[-1])
else:
    print(-1)

'''

Solution (Python):
def resolve():
    N,M = map(int,input().split())

    DP = [10 ** 8  + 1 for _ in range(1 << N)]
    DP[0] = 0

    for _ in range(M):
        a,_ = map(int,input().split())
        c = list(map(int,input().split()))
        bit = 0
        for j in c:
            bit |= 1 << (j-1)
        for j in range(1 << N):
            DP[j | bit] = min(DP[j]+a,DP[j|bit])
    print(DP[-1] if DP[-1] != 10 ** 8 + 1 else -1)
resolve()

Solution (Python):
n,m=[int(j) for j in input().split()]
dp=[10**18]*(2**(n))
dp[0]=0
cost=[]
for i in range(m):
    x,y=[int(j) for j in input().split()]
    tmp=set([int(j) for j in input().split()])
    ind=0
    for j in range(1,n+1):
        if j in tmp:
            ind|=2**(j-1)
    dp[ind]=x
    cost.append((ind,x))

for i in range(2**n):
    for j in range(m):
        dp[i|cost[j][0]]=min(dp[i|cost[j][0]],dp[i]+cost[j][1])

if dp[-1]!=10**18:
    print(dp[-1])
else:
    print(-1)

Solution (Python):
n,m=[int(j) for j in input().split()]
dp=[10**8]*(2**n)
dp[0]=0
cost=[]
for i in range(m):
    x,y=[int(j) for j in input().split()]
    tmp=[int(j) for j in input().split()]
    ind=0
    for j in tmp:
        ind|=1<<(j-1)
    cost.append((ind,x))

for i in range(1<<n):
    for j in range(m):
        dp[i|cost[j][0]]=min(dp[i|cost[j][0]],dp[i]+cost[j][1])

if dp[-1]!=10**8:
    print(dp[-1])
else:
    print(-1)

Solution (Python):
n,m=map(int,input().split())
keys=[None]*m
dp=[-1]*(2**n)
dp[0]=0
for i in range(m):
  a,b=map(int,input().split())
  c=list(map(int,input().split()))
  cond=0
  for j in c:
    cond+=2**(j-1)
  keys[i]=[a,cond]
for key in keys:
  for sta in range(2**n):
    if dp[sta]==-1:continue
    if dp[sta|key[1]]==-1:
      dp[sta|key[1]]=key[0]+dp[sta]
    else:
      dp[sta|key[1]]=min(dp[sta|key[1]],dp[sta]+key[0])
print(dp[-1])

Solution (Python):
n,m=map(int,input().split())
keys=[None]*m
dp=[-1]*(2**n)
dp[0]=0
for i in range(m):
  a,b=map(int,input().split())
  c=list(map(int,input().split()))
  cond=0
  for j in c:
    cond+=2**(j-1)
  keys[i]=[a,cond]
for key in keys:
  for sta in range(2**n):
    if dp[sta]==-1:continue
    if dp[sta|key[1]]==-1:
      dp[sta|key[1]]=key[0]+dp[sta]
    else:
      dp[sta|key[1]]=min(dp[sta|key[1]],dp[sta]+key[0])
print(dp[-1])

Solution (Python):
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
kagi=[[]for _ in range(m)]
for _ in range(m):
    a,b=map(int,input().split())
    c=list(map(int,input().split()))
    kagi[_].append(a)
    kagi[_].append(c)

dp=[10**7 for _ in  range(2**n)]
dp[0]=0
for i in range(2**n):
    for j in range(m):
        l=kagi[j][1]
        ni=0
        for k in l:
            ni+=2**(k-1)
        dp[ni|i]=min(dp[ni|i],dp[i]+kagi[j][0])

if dp[-1]==10**7:
    print(-1)
else:
    print(dp[-1])

Solution (Python):
import sys


def main():
    n, m = [int(s) for s in sys.stdin.readline().strip().split()]
    a = [0] * m
    c = [0] * m
    inf = float('inf')

    for i in range(m):
        ai, bi = [int(s) for s in sys.stdin.readline().strip().split()]
        a[i] = ai
        ci = [int(s)-1 for s in sys.stdin.readline().strip().split()]
        
        c_val = sum([2 ** num for num in ci])
        c[i] = c_val

    dp = [[inf] * (2 ** n) for _ in range(m)]
    for i in range(m):
        dp[i][0] = 0

    for j in range(2 ** n):
        first_key_boxes = c[0]
        if first_key_boxes & j == j:
            dp[0][j] = a[0]

    for i in range(1, m):
        for j in range(1, 2 ** n):
            prev = j & (~c[i])
            dp[i][j] = min(dp[i-1][j], a[i] + dp[i-1][prev])
    if dp[m-1][2**n-1] == inf:
        print(-1)
    else:
        print(dp[m-1][2**n-1])


main()

Solution (Python):
n,m = map(int,raw_input().split())

M = 1<<n
dp = [10**9]*M
dp[0] = 0
for i in xrange(m):
	a,b = map(int,raw_input().split())
	c = map(int,raw_input().split())
	mask = 0
	for x in c:
		mask += 1<<(x-1)
	for j in xrange(M):
		dp[j|mask] = min(dp[j|mask], dp[j]+a)
	
 
if dp[M-1] >= 10**9:
	print -1
else:
	print dp[M-1]

Solution (Python):
def main():
    import sys
    input = sys.stdin.buffer.readline
    N, M = (int(i) for i in input().split())
    ABC = []
    c_all_or = 0
    where_open = lambda s: sum(2**j for j in s)
    for i in range(M):
        a, b = (int(j) for j in input().split())
        c = {int(j)-1 for j in input().split()}
        wc = where_open(c)
        c_all_or |= wc
        ABC.append((a,b,wc))
    if c_all_or != ((1<<N) - 1):
        print(-1)
        return 0
    r = [10**9] * (1<<N)
    r[0] = 0
    for bit in range(1,1<<N):
        q = r[bit]
        for i in range(M):
            cur = ABC[i][2]
            less = (bit ^ cur) & bit
            q = min(q,r[less] + ABC[i][0])
        r[bit] = q
    
    print(r[(1<<N) - 1])
if __name__ == '__main__':
    main()

Solution (Python):
f,*L=open(0).readlines()
n,m=map(int,f.split())
t=[(int(a.split()[0]),list(map(int,b.split()))) for a,b in zip(*[iter(L)]*2)]
K=[]
for a,C in t:
  r=0
  for c in C:
    r|=2**(c-1)
  K.append((a,r))
INF=float('inf')
dp=[INF]*(2**n)
dp[0]=0
for g in range(2**n):
  for a,c in K:
    if dp[g|c]>dp[g]+a:
      dp[g|c]=dp[g]+a
print(-1 if dp[-1]==INF else dp[-1])

Solution (Python):
import sys
input=sys.stdin.readline
N,M=map(int,input().split())

L={}
for i in range(M):
    a,b=map(int,input().split())
    c=list(map(int,input().split()))
    d=0
    for j in c:
        d+=2**(N-j)
    if d not in L:
        L[d]=a
    else:
        if L[d]>a:
            L[d]=a


D={}
D[0]=0
C=0
for i in range(N):
    C+=2**(N-1-i)
    E={}
    for j in D:
        for k in L:
            if j>=C:
                if j not in E:
                    E[j]=D[j]
                else:
                    if E[j]>D[j]:
                        E[j]=D[j]
            if j|k>=C:
                if j|k not in E:
                    E[j|k]=D[j]+L[k]
                else:
                    if E[j|k]>D[j]+L[k]:
                        E[j|k]=D[j]+L[k]
    
    D=E
if len(D)==0:
    print(-1)
else:
    print(D[2**N-1])

Solution (Python):
n, m = map(int, input().split(" "))
a = [0] * m
b = [0] * m
c = [[]] * m
INF = int(10e8)
dp = [INF] * (2 ** n)
dp[0] = 0
for i in range(m):
    a[i], b[i] = map(int, input().split(" "))
    c[i] = list(map(int, input().split(" ")))

for i in range(m):
    keyState = 0
    for j in c[i]:
        key = 1 << j - 1
        keyState = keyState | key
    for k in range(2**n):
        nextState = k | keyState
        dp[nextState] = min(dp[nextState], dp[k] + a[i])
if dp[-1] == INF:
    print(-1)
else:
    print(dp[-1])

Solution (Python):

n,m=map(int,input().split())
ab=[]
c=[]
inf=float("inf")
for i in range(m):
    ab.append(list(map(int,input().split())))
    lst=list(map(int,input().split()))
    num=0
    for u in lst:
        num+=2**(u-1)
    c.append(num)
dp=[[inf]*(2**n) for _ in range(m+1)]
for i in range(m):
    dp[i][0]=0
for i in range(m):
    for j in range(2**n):
        if dp[i][j]!=inf:
            dp[i+1][j|c[i]]=min(dp[i+1][j|c[i]],dp[i][j]+ab[i][0])
            dp[i+1][j]=min(dp[i+1][j],dp[i][j])
if dp[m][2**n-1]!=inf:
    print(dp[m][2**n-1])
else:
    print(-1)

Solution (Python):
def main():
    n, m = map(int, input().split(' '))
    dp = [10**9 for _ in range(2**n)]
    dp[0] = 0
    for i in range(m):
        a, b = map(int, input().split(' '))
        c = list(map(int, input().split(' ')))
        num = 0
        for j in range(b):
            num += 1 << (c[j]-1)
        for s in range(2**n):
            if dp[s|num] >= dp[s] + a:
                dp[s|num] = dp[s] + a
    if dp[-1] == 10**9:
        print(-1)
    else:
        print(dp[-1])
if __name__ == '__main__':
    main()

Solution (Python):
n, m = map(int, input().split(' '))
dp = [10**9 for _ in range(2**n)]
dp[0] = 0
for i in range(m):
    a, b = map(int, input().split(' '))
    c = list(map(int, input().split(' ')))
    num = 0
    for j in range(b):
        num += 1 << (c[j]-1)
    for s in range(2**n):
        if dp[s|num] >= dp[s] + a:
            dp[s|num] = dp[s] + a
if dp[-1] == 10**9:
    print(-1)
else:
    print(dp[-1])

Solution (Python):




def main():
  n, m = map(int, input().split())
  ps = [1e+9] * (2 ** n)
  ps[0] = 0

  for _ in range(m):
    p, _ = map(int, input().split())
    k = 0

    for i in map(int, input().split()):
      k |= 1 << (i - 1)

    for i in range(len(ps)):
      s = k | i
      ps[s] = min(ps[i] + p, ps[s])

  if ps[-1] == 1e+9:
    ps[-1] = -1

  print(ps[-1])


if __name__ == '__main__':
  main()

Solution (Python):
n,m = map(int,input().split())
l = []
wa = 0
for i in range(m):
    a,b = map(int,input().split())
    c = list(map(int,input().split()))
    wa += a
    l.append([a,b,c])
dp = [[wa + 1 for i in range(2**n)] for i in range(m+1)]
bit = 2**n

for i in range(1,m+1):
    a,b,c = l[i-1]
    bitc = 0
    for x in c:
        bitc += 2**(x-1)
    for j in range(bit):
        j2 = j
        mod = 1
        for k in range(n):
            if (j >> k) & 1:
                continue
            else:
                if (bitc >> k) & 1:
                    j2 += 2**k
        
        if j == 0:
            dp[i][j2] = min([dp[i-1][j2],a,dp[i][j2]])
        else:
            dp[i][j2] = min([dp[i-1][j]+a,dp[i-1][j2],dp[i][j2]])
        if j2 != j:
            dp[i][j] = dp[i-1][j]
ans = dp[m][bit-1]

if ans <= wa:
    print(dp[m][bit-1])
else:
    print(-1)

Solution (Python):

N, M = map(int, input().split())
A = [0] * M
B = [0] * M
C = [0] * M
for i in range(M):
    A[i], B[i] = map(int, input().split())
    C[i] = list(map(int, input().split()))


dp = [9**9]* (1<<N)

def list_to_bin(my_list):
    my_bin = 0
    for l in my_list:
        my_bin += 1<<(l-1)
    return my_bin

for i in range(M):
    C[i] = list_to_bin(C[i])

dp[0] = 0
for i in range(M):
    for s in range(1<<N):
        dp[s|C[i]] = min(dp[s|C[i]], dp[s] + A[i])

if dp[-1] == 9**9:
    print(-1)
else:
    print(dp[-1])