Problem:
Exhaustive Search Write a program which reads a sequence A of n elements and an integer M , and outputs " yes " if you can make M by adding elements in A , otherwise " no ". You can use an element only once. You are given the sequence A and q questions where each question contains M i . Input In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers ( M i ) are given. Output For each question M i , print yes or no . Constraints  n ≤ 20  q ≤ 200  1 ≤ elements in A ≤ 2000  1 ≤ M i ≤ 2000  Sample Input 1 5
1 5 7 10 21
8
2 4 17 8 22 21 100 35 Sample Output 1 no
no
yes
yes
yes
yes
no
no Notes You can solve this problem by a Burte Force approach. Suppose solve(p, t) is a function which checkes whether you can make t by selecting elements after p-th element (inclusive). Then you can recursively call the following functions: solve(0, M) solve(1, M-{sum created from elements before 1st element}) solve(2, M-{sum created from elements before 2nd element}) ... The recursive function has two choices: you selected p-th element and not. So, you can check solve(p+1, t-A[p]) and solve(p+1, t) in solve(p, t) to check the all combinations. For example, the following figure shows that 8 can be made by A[0] + A[2].

Solution (Python):
from sys import stdin

n = int(input())
A = list(map(int, stdin.readline().split()))
q = int(input())
m = list(map(int, stdin.readline().split()))

def solve(i,m):
    '''
    i番目以降の要素を使用してmを作れる場合、trueを返す
    '''
    if m == 0:
        return True
    if sum(A[i:]) < m:
        return False
    if i >= n:
        return False
    res = solve(i+1,m) or solve(i+1,m-A[i])
    return res

for a in m:
    if solve(0,a):
        print("yes")
    else:
        print("no")

Solution (Python):
def part_sum(a,A):
    
    N=len(a)
    dp=[[-1 for i in range(A+1)] for j in range(N+1)]
    dp[0][0]=[]
    
    for i in range(N):
        for j in range(A+1):
            if a[i]<=j: 
                if dp[i][j] != -1:
                    dp[i+1][j] = dp[i][j]
                elif dp[i][j-a[i]] != -1:
                    dp[i+1][j] = dp[i][j-a[i]]+[a[i]]
            else: 
                dp[i+1][j]=dp[i][j]
    
    """
    num_list = {}
    for i in dp:
        for num,j in enumerate(i):
            if j != -1:
                num_list[num] = j
    return num_list
    """
    return dp[N][A]
a = int(input())
num = list(map(int,input().split()))
q = int(input())
ans = list(map(int,input().split()))
for i in ans:
    check = part_sum(num,i)
    
    if check == -1:
        print("no")
    else:
        print("yes")

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())
    m = list(map(int, input().split()))

    res = list()

    def mul(a, b):
        return a * b


    
    
    
    
    
    
    
    
    
    
    

    def dfs(A):
        
        if len(A) == n:
            
            res.append(sum(list(map(mul, a, A))))
            return
        for v in range(2):
            A.append(v)
            dfs(A)
            A.pop()
    dfs([])
    for i in m:
        if i in res:
            print('yes')
        else:
            print('no')

if __name__ == '__main__':
    main()

Solution (Python):
def resolve():
    n = int(input())
    A = [int(i) for i in input().split()]
    ans = [False] * 2001
    for i in range(2**n):
        sumA = 0
        for j in range(n):
            if (i >> j) & 1:
                sumA += A[j]
        ans[sumA] = True
    q = int(input())
    M = [int(i) for i in input().split()]
    for m in M:
        if ans[m]:
            print("yes")
        else:
            print("no")


resolve()

Solution (Python):
def solve(n,A):
    x=pow(2,n)
    dp=[False]*2001
    for i in range(x):
        count=0
        for j in range(n):
            if (i>>j)&1:
                count+=A[j]
        if count<=2000:
            dp[count]=True
    return dp

n=int(input())
A=list(map(int,input().split()))
q=int(input())
m=list(map(int,input().split()))
ans=solve(n,A)
for i in range(q):
    if ans[m[i]]:
        print("yes")
    else:
        print("no")

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
q = int(input())
m = [int(i) for i in input().split()]

ok = [[0 for i in range(2001)] for j in range(21)]
ok[0][0] = 1

for i in range(n):
    for j in range(2001):
        if j+a[i] > 2000:
            ok[i+1][j] = max(ok[i][j], ok[i+1][j])
        else:
            ok[i+1][j] = max(ok[i][j], ok[i+1][j])
            ok[i+1][j+a[i]] = max(ok[i][j], ok[i+1][j+a[i]])

for i in m:
    print('yes' if ok[n][i] else 'no')

Solution (Python):
def main():
    import sys, itertools as ite
    n = int(sys.stdin.readline())
    A = tuple(map(int, sys.stdin.readline().split()))
    
    q = int(sys.stdin.readline())
    M = map(int, sys.stdin.readline().split())
    bit = ite.product([0,1], repeat=n)
    ans = []
    for b in bit:
        tmp = 0
        for i in range(n):
            tmp +=b[i]*A[i]
        ans += [tmp]
        
    for m in M:
        if m in ans:
            print('yes')
        else:
            print('no')







if __name__=='__main__':
    main()

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))

for x in M:
  dp = [[0 for _ in range(x+1)] for _ in range(n+1)]
  dp[0][0]=1
  for i in range(n):
    for j in range(x+1):
      if A[i] <= j:
        dp[i+1][j] = dp[i][j - A[i]] or dp[i][j]
      else:
        dp[i+1][j] = dp[i][j]

  if dp[n][x] == 1:
    print ('yes')
  else:
    print ('no')

Solution (Python):
import sys

n = int(sys.stdin.readline())
A = [int(x) for x in sys.stdin.readline().split()]
q = int(sys.stdin.readline())
Qs = [int(x) for x in sys.stdin.readline().split()]

l = len(A)
N = 2000
dp = [False] * (N+1)
dp[0] = True

for a in A:
    tmp = dp.copy()
    for j in range(N+1):
        if j + a > N:break

        if tmp[j]:
            dp[j+a] = True

for m in Qs:
    if dp[m]:
        print("yes")
    else:
        print("no")

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]

n  = int(input())
A = list(map(int, input().split()))
q  = int(input())
M = list(map(int, input().split()))

def solve(dp, n,A, i,m):
    if m==0:
        return True
    
    elif i>=n:
        return False
    
    elif dp[i][m] is not None:
        return dp[i][m]
    
    elif solve(dp,n,A, i+1,m):
        dp[i][m] = True
        return True
    
    elif m-A[i]>=0:
        dp[i][m] = solve(dp,n,A, i+1,m-A[i])
        return dp[i][m]
    
    else:
        dp[i][m]= False
        return False
    

dp = [[None for i in range(max(M)+1)] for j in range(n+1)]

for m in M:    
    if solve(dp, n,A, 0, m):
        print('yes')
    else:
        print('no')

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))

def make_list(A):
    n = len(A)
    result = []
    for i in range(2**n):
        tmp = 0
        if i == 0:
            idx = ['0' for _ in range(n)]
        else:
            idx = list(bin(i).lstrip('0b').zfill(n))
        for num, j in enumerate(idx):
            if j == '1':
                tmp += A[num]
        result.append(tmp)
    return result


res = make_list(A)
for i in m:
    if i in res:
        print('yes')
    else:
        print('no')

Solution (Python):
def solve(n, A, q, m):
    memo = dict()
    for i in range(2**n):
        tmp = 0
        for j in range(n):
            if i >> j & 1:
                tmp += A[j]
        memo[tmp] = 1

    for val in m:
        print("yes" if val in memo else "no")

if __name__ == "__main__":
    n = int(input())
    A = list(map(int, input().split()))
    q = int(input())
    m = list(map(int, input().split()))
    solve(n, A, q, m)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
q=int(input())
m=list(map(int,input().split()))
l=[]
for i in range(2**n):
    sub=0
    for j in range(n):
        if (i>>j)&1==1:
            sub+=a[j]
    l.append(sub)
for i in m:
    if i in l:
        print("yes")
    else:
        print("no")

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))
T = set()
for i in range(1, 2 ** n):
    total = 0
    for j in range(n):
        if i >> j & 1:
            total += A[j]
    T.add(total)
for m in M:
    if m in T:
        print('yes')
    else:
        print('no')

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
q = int(input())
m = list(map(int,input().split()))
"""def dfs(i,m):
    global a
    if i == 0:
        if m == 0:
            return True
        else:
            return False
    if dfs(i-1, m):
        return True
    if dfs(i-1,m - a[i-1]): 
        return True
    return False
for i in range(q):
    if dfs(n,m[i]):
        print("yes")
    else:
        print("no")"""
b = []
def dfs(i,m):
    global b
    if i == 0:
        b.append(m)
    else:
        dfs(i-1,m)
        dfs(i-1,m+a[i-1])
    return b
b = dfs(n,0)
for i in range(q):
    if m[i] in b:
        print("yes")
    else:
        print("no")

Solution (Python):
from sys import stdin

input = stdin.readline

n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))

set_m = set([])

for i in range(2 ** n):
    tmp = 0
    for j in range(n):
        if (i >> j) & 1:
            tmp += A[j]

    set_m.add(tmp)

for i in m:
    if i in set_m:
        print("yes")
    else:
        print("no")

Solution (Python):
n = int(input())

a = list(map(int, input().split()))

q = int(input())

m = dict(zip(range(q), list(map(int, input().split()))))

ans = ["no"] * q

for i in range(2**n):
    now = 0
    for j in range(n):
        if i >> j & 1:
            now += a[j]

    if now in m.values():
        key_lst = [key for key, value in m.items() if value==now]
        for key in key_lst:
            ans[key] = "yes"

for i in range(q):
    print(ans[i])

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
m=int(input())
q=list(map(int,input().split()))
num_list=set()
for i in range(2**N):
    ans=0
    for j in range(N):
        if i>>j&1:
            ans+=A[j]
    num_list.add(ans)
for i in q:
    if i in num_list:
        print("yes")
    else:print("no")

Solution (Python):
import itertools
n = int(input())
a = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))

able = [0] * (max(n * max(a) + 1, 2001))
for item in itertools.product([0, 1], repeat=n):
    total = sum([i * j for i, j in zip(a, item)])
    able[total] = 1

for m in M:
    print('yes' if able[m] else 'no')

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
B = list(map(int, input().split()))

s = set()
def check(i, m):
    if i == n:
        s.add(m)
        return
    check(i+1, m+A[i])
    check(i+1, m)

check(0,0)

for i in B:
    if i in s:
        print('yes')
    else:
        print('no')

Solution (Python):

n = (int)(input())
a = list(map(int, input().split(" ")))
q = (int)(input())
m = list(map(int, input().split(" ")))
lst = []
for i in range(2 ** n, 0, -1):
    temp = 0
    for j in range(n):
        if (i >> j) & 1:
            temp += a[j]
    lst.append(temp)
for k in range(q):
    if m[k] in lst:
        print("yes")
    else:
        print("no")

Solution (Python):
n = int(input())
A = list(map(int , input().split()))
q = int(input())
B = list(map(int , input().split()))

ans = []

for bit in range(1<<n):
    tmp = 0
    for i in range(n):
        if bit & (1<<i):
            tmp += A[i]
    ans.append(tmp)

for j in range(q):
    if B[j] in ans:
        print("yes")
    else:
        print("no")

Solution (Python):
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect
import functools

@functools.lru_cache(None)
def dfs(i,sum_v,val):
    if i == n:
        return sum_v == val
    if dfs(i+1,sum_v,val):
        return True
    if dfs(i+1,sum_v + A[i],val):
        return True
    return False
n = int(input())
A = list(map(int,input().split()))
q = int(input())
m = list(map(int,input().split()))

for i in range(q):
    if dfs(0,0,m[i]):
        print("yes")
    else:
        print("no")

Solution (Python):



def rec(a, use):
    if use >= N:
        memo[a] = True
        return
    _next = A[use]
    rec(a+_next,use+1)
    rec(a,use+1)


N = int(input())
A = list(map(int, input().split()))
Q = int(input())
M = list(map(int, input().split()))

memo = [False]*2000
rec(0, 0)

for i in M:
    if memo[i]:
        print('yes')
    else:
        print('no')

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
q = int(input())
m = list(map(int,input().split()))
sumA = sum(A)
def solve(i,m):
    if m == 0:
        return 1
    if i >= n:
        return 0
    rec =  solve(i+1,m) or solve(i+1, m - A[i])
    return rec
for i in m:
    if i >= sumA:
        print("no")
    else:
        if solve(0,i):
            print("yes")
        else:
            print("no")

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
m = int(input())
q = list(map(int, input().split()))

ans = []
for i in range(2**n):
    cnt = 0
    for j in range(n):
        if ((i>>j)&1): cnt += a[j]
    ans.append(cnt)
for x in q:
    print('yes' if (x in ans) else 'no')

Solution (Python):
import sys
from collections import deque

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

n = I()
A = LI()
q = I()
m = LI()
ans = 0
partial_sum = set()
for i in range(2 ** n):
    bit = [i>>j&1 for j in range(n)]
    partial_sum.add(sum(A[k]*bit[k] for k in range(n)))
for x in m:
    print('yes' if x in partial_sum else 'no')

Solution (Python):




def solve(i, m):
    global A, n

    if (m == 0):
        return True
    if (i >= n):
        return False

    res = solve(i + 1, m) or solve(i + 1, m - A[i])

    return res


if __name__ == "__main__":
    n = int(input())
    A = [int(i) for i in input().split()]
    q = int(input())
    m = [int(i) for i in input().split()]
    total = sum(A)
    for m_i in m:
        if m_i > total:
            print('no')
        else:
            print('yes' if solve(0, m_i) else 'no')

Solution (Python):
from itertools import product

n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))
a_sum = set()


for a in product(*((x,0) for x in A)):
    a_sum.add(sum(a))

for m in M:
    if m in a_sum:
        print("yes")
    else:
        print("no")

Solution (Python):
from itertools import product

n = int(input())
A = map(int,input().split())
sums = set(map(sum,product(*((0,a) for a in A))))
q = int(input())
for m in map(int,input().split()):
    print('yes' if m in sums else 'no')

Solution (Python):
n=int(input())
S=[int(i) for i in input().split()]
q=int(input())
T=[int(i) for i in input().split()]


def solve(i,m,n,S):
    if sum(S)<m:
        return False
        
    if m==0:
        return True

    elif i>=n:
        return False
        
    res=solve(i+1,m,n,S) or solve(i+1,m-S[i],n,S)
    return res
    
for i in range(q):
    attempt=solve(0,T[i],n,S)
    if attempt:
        print("yes")
        
    else:
        print("no")

Solution (Python):
from itertools import product

n = int(input())
A = tuple(map(int, input().split(' ')))
q = int(input())
M = tuple(map(int, input().split(' ')))

numbers = set()
for bits in product((0, 1), repeat=n):
    numbers.add(sum([a * b for a, b in zip(A, bits)]))

for m in M:
    if m in numbers:
        print('yes')
    else:
        print('no')

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


def bitsearch():
  nums = [0] * (2 ** N)
  for i in range(2 ** N):
    num = 0
    for j in range(N):
      if (i >> j) & 1:
        num += A[j]
        nums[i] = num
  for q in range(Q):
    if M[q] in nums:
      print("yes")
    else:
      print("no")

bitsearch()

Solution (Python):
import itertools

n = int(input())
a = list(map(int,input().split()))
q = int(input())
m = list(map(int,input().split()))

data = []
for i in itertools.product(range(2),repeat=n):
    data.append(sum([i[j]*a[j] for j in range(n)]))
    
for i in m:
    if i in data:
        print("yes")
    else:
        print("no")

Solution (Python):
n = int(input())
A = [int(j) for j in input().split()]
q = int(input())
m = [int(j) for j in input().split()]
total = []
for i in range(2**n):
    bag = []
    for j in range(n):
        if ((i>>j)&1):
            bag.append(A[j])
    total.append(sum(bag))

for m1 in m:
    if m1 in set(total):
        print('yes')
    else:
        print('no')

Solution (Python):
n = int(input())
A = tuple(map(int, input().split()))
q = int(input())
M = tuple(map(int, input().split()))

sums = set()
from collections import deque
st = deque([[0, 0], [0, A[0]]])
while st:
    i, s = st.pop()
    i += 1
    if i == n:
        sums.add(s)
        continue
    st.append([i, s])
    st.append([i, s+A[i]])

for m in M:
    print('yes' if m in sums else 'no')

Solution (Python):
def solve(m,ans):
    global L,S
    if m == len(L):
        S.add(ans)
    else:
        solve(m+1,ans+L[m])
        solve(m+1,ans)

n = int(input())
S = set([])
L = list(map(int,input().split()))
q = int(input())
solve(0,0)
for i in map(int,input().split()):
    if i in S:
        print("yes")
    else:
        print("no")

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
q = int(input())
m = list(map(int,input().split()))

s = [list(map(int,bin(x)[2:].zfill(n))) for x in range(2**n)]

anset=set()
for j in s:
    ans=0
    for k in range(n):
        ans+=a[k]*j[k]
    anset.add(ans)

for i in range(q):
    if m[i] in anset:
        print('yes')
    else:
        print('no')

Solution (Python):
n = int(input())
A = [int(i) for i in input().split()]

q = int(input())
m = [int(i) for i in input().split()]


def dfs(idx, s, target):
    if s == target:
        return 1
    if s > target or idx == n:
        return 0
    if s + sum(A[idx:]) < target:
        return 0

    return dfs(idx+1, s, target) or dfs(idx+1, s + A[idx], target)


for i in m:
    ans = 'yes' if dfs(0, 0, i) else 'no'
    print(ans)

Solution (Python):
if __name__ == '__main__':
    n = int(input())
    t = list(map(int, input().split()))
    m = int(input())
    s = list(map(int, input().split()))

    def solve(i, mm):
        if mm == 0:
            return True
        if i >= n:
            return False
        if sum(t[i::]) < mm:
            return False
        res = solve(i + 1, mm) or solve(i + 1, mm - t[i])
        return res

    for r in s:
        print('yes' if solve(0, r) else 'no')

Solution (Python):
def solve(i, m):

    if i >= n:
        combs.add(m)
        return

    solve(i+1, m)
    solve(i+1, m+A[i])


def main():
    global n
    global A
    global combs
    n = int(input())
    A = list(map(int, input().split()))
    _ = int(input())
    Q = list(map(int, input().split()))
    
    combs = set()
    solve(0, 0)

    for q in Q:
        if q in combs:
            print("yes")
        else:
            print("no")


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))

max = max(m)

dp = [[0 for _ in range(max + 1)] for __ in range(n + 1)]
dp[0][0] = 1
for j in range(n):
  for k in range(max + 1):
    if k >= A[j] and dp[j][k - A[j]]:
      dp[j + 1][k] = 1
    elif dp[j][k]:
      dp[j + 1][k] = 1
for i in range(q):
  if dp[n][m[i]]:
     print("yes")
  else:
    print("no")

Solution (Python):
from itertools import product

n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))

cases = product([0, 1], repeat=n)

seen = set()

for case in cases:
    sum_ = 0
    for i in range(n):
        sum_ += case[i] * A[i]
    seen.add(sum_)

for target in M:
    if target in seen:
        print('yes')
    else:
        print('no')

Solution (Python):
import sys


input = sys.stdin.readline


def make_sum_set(i, v):
    if i == N:
        S.add(v)
        return
    else:
        make_sum_set(i+1, v)
        make_sum_set(i+1, v+A[i])


def main():
    make_sum_set(0, 0)
    for m in M:
        if m in S:
            print("yes")
        else:
            print("no")


if __name__ == "__main__":
    N = int(input())
    A = [int(a) for a in input().split()]
    Q = int(input())
    M = [int(m) for m in input().split()]
    S = set()
    main()

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
q = int(input())
m = list(map(int,input().split()))

cnt = [0] * (2000 * 20)

for i in range(1, 2**n + 1):
    SUM = 0
    for j in range(n):
        if i>>j & 1:
            SUM += a[j]
    cnt[SUM] = 1

for _m in m:
    if cnt[_m] == 1:
        print("yes")
    else:
        print("no")

Solution (Python):
def solve(i, m):
    if (i, m) in solved_dict:
        return solved_dict[(i, m)]
    if m == 0:
        return True
    if m < 0:
        return False
    if i >= n:
        return False
    solved_dict[(i, m)] = solve(i + 1, m - A[i]) or solve(i + 1, m)
    return solved_dict[(i, m)]

solved_dict = {}
n = int(input())
A = list(map(int, input().split()))
q = int(input())
for m in list(map(int, input().split())):
    print("yes" if solve(0, m) else "no")

Solution (Python):
import sys
from sys import stdin
input = stdin.readline

n = int(input())
A =[int(x) for x in input().split()]
q = int(input())
M =[int(x) for x in input().split()]

dp = [[-1 for i in range(2001)] for j in range(21)]

def solve(i,m):
    if dp[i][m] != -1:
        return dp[i][m]
    if m == 0:
        dp[i][m] = True
    elif i >= n:
        dp[i][m] = False
    elif solve(i+1,m):
        dp[i][m] = True
    elif solve (i+1, m-A[i]):
        dp[i][m] = True
    else:
        dp[i][m] = False
    return dp[i][m]

for m in M:
    if solve(0,m):
        print("yes")
    else:
        print("no")

Solution (Python):
def readinput():
    n = int(input())
    a = list(map(int,input().split()))
    q = int(input())
    m = list(map(int,input().split()))
    return n,a,q,m

def canmake(a,i):
    if(len(a)==1):
        if(a==i):
            return True
        else:
            return False

    for j in range(len(a)):
        ii = i-a[j]
        can=canmake(a[:j-1]+a[j+1:],ii) 
        if(can==True):
            return True
    return False   


def main(n,a,q,m):
    for i in m:
        ans=canmake(a,i)
        if(ans==True):
            print('yes')
        else:
            print('no')
    return

def solve(a,i,m):
    if(m==0):
        return True
    if(i>=len(a)):
        return False
    return solve(a,i+1,m) or solve(a,i+1,m-a[i])

def main2(n,a,q,m):
    for mm in m:
        ans=solve(a,0,mm)
        if(ans==True):
            print('yes')
        else:
            print('no')


def main3():
    global n
    global a
    n=int(input())
    a=list(map(int,input().split()))
    q=int(input())
    ms=list(map(int,input().split()))
    for m in ms:
        ans=solve2(0,m)
        if(ans==True):
            print('yes')
        else:
            print('no')

def solve2(i,m):
    global n
    global a
    if(m==0):
        return True
    if(i>=n):
        return False
    return solve2(i+1,m) or solve2(i+1,m-a[i])

def main4():
    n = int(input())
    a = list(map(int,input().split()))
    q = int(input())
    m = list(map(int,input().split()))

    S = [0]*(2**n)
    
    for i in range(2**n):
        b=1
        for j in range(n):
            
            if ( i&b == b):
                S[i] += a[j]
            b*=2
    

    for mm in m:
        if (mm in S):
            print('yes')
        else:
            print('no')



if __name__=='__main__':
    
    main4()

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))

"""
def exhaustive_search(m, i):
    if i == n:
        return 0
    if m < 0:
        return 0
    if m == A[i]:
        return 1
    return max(exhaustive_search(m, i + 1), exhaustive_search(m - A[i], i + 1))
"""

def dp_search(m):
    dp = [[1] + [0] * m for _ in range(n + 1)] 
    for i in range(1, n+1):
        for j in range(1, m+1):
            if j >= A[i-1]:
                dp[i][j] = max(dp[i-1][j], dp[i-1][j - A[i-1]])
            else:
                dp[i][j] = dp[i-1][j]
    return dp[n][m]

for mi in m:
    if dp_search(mi):
        print("yes")
    else:
        print("no")

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
nums = list(map(int, input().split()))

sum_set = set()
for i in range(1, 2 ** n):
    total = 0
    for j in range(n):
        if i >> j & 1:
            total += A[j]
    sum_set.add(total)

for num in nums:
    print('yes' if num in sum_set else 'no')

Solution (Python):
import itertools

n = input()
a = list(map(int, input().split()))
q = input()
 
aset = set()
for i in range(1, len(a) + 1):
    aset |= set(sum(combi) for combi in itertools.combinations(a, i))

for m in map(int, input().split()):
    print('yes' if m in aset else 'no')

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
M = list(map(int, input().split()))
flag = [False] * 2000

for i in range(2 ** n):
    total = 0
    for j in range(n):
        if((i >> j) & 1):
            total += A[j]
    flag[total] = True
for m in M:
    print('yes' if flag[m] else 'no')

Solution (Python):

import sys

n = int(input())
A = list(map(int, sys.stdin.readline().strip().split()))
q = int(input())
m = list(map(int, sys.stdin.readline().strip().split()))

sum_set = set()

for i in range(2 ** n):
    bit = [(i >> j) & 1 for j in range(n)]
    combined = [x * y for (x, y) in zip(A, bit)]
    sum_set.add(sum(combined))

for target in m:
    if target in sum_set:
        print('yes')
    else:
        print('no')

Solution (Python):



n = int(input())
A = [int(e) for e in input().split()]
q = int(input())
M = [int(e) for e in input().split()]

def solve(i,m):
    if m == 0:
        return True
    if i >= n:
        return False
    if m > sum(A[i:]):
        return False
    res = solve(i + 1,m) or solve(i + 1,m - A[i])
    return res
    
for m in M:
    if(solve(0,m)):
        print("yes")
    else:
        print("no")

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))

value = []
for i in range(2 ** n):
    ans = 0
    for j in range(n):  
        if ((i >> j) & 1):  
            ans += a[j]
    value.append(ans)  

for mm in range(len(m)):          
    if m[mm] in value:
        print("yes")
    else:
        print("no")

Solution (Python):
import itertools
n = int(input())
A = list(map(int,input().split()))
q = int(input())
M = list(map(int,input().split()))

dp = []
for i in itertools.product([0, 1], repeat=n):
    tmp = 0
    for j in range(n):
        tmp += A[j] * i[j]
    dp.append(tmp)

for i in M:
    if i in dp:
        print('yes')
    else:print('no')

Solution (Python):
import itertools

def check(lst, n, x):
    for i in range(2, n+1):
        B = list(itertools.combinations(lst,i))
        for C in B:
            if x == sum(C):
                return True
    return False

n = int(input())
A = [int(i) for i in input().split()]
q = int(input())
m = [int(i) for i in input().split()]

for x in m:
    if x > sum(A):
        print("no")
    elif (x in A) or check(A, n, x):
        print("yes")
    else:
        print("no")

Solution (Python):
dp = {}

n = int(input())
a = [int(i) for i in input().split()]

q = int(input())
ms = [int(i) for i in input().split()]

def solve(i, m):
  global n, a

  if  (i, m) in dp:
    return dp[(i, m)]

  if m == 0:
    dp[(i, m)] = True
  elif n <= i:
    dp[(i, m)] = False
  elif solve(i + 1, m):
    dp[(i, m)] = True
  elif solve(i + 1, m - a[i]):
    dp[(i, m)] = True
  else:
    dp[(i, m)] = False
  
  return dp[(i, m)]

for m in ms:
  if solve(0, m):
    print('yes')
  else:
    print('no')

Solution (Python):

def rec(i, w):
	if dp[i][w] != -1:
		return dp[i][w]

	if i == 0:
		if w == 0:
			return True
		else:
			return False

	res = 0
	if w >= a[i - 1] and rec(i - 1, w - a[i - 1]) == 1:
		res = 1
	
	if rec(i - 1, w) == 1:
		res = 1

	dp[i][w] = res
	return dp[i][w]

n = int(input())
a = list(map(int, input().split()))
m = int(input())
q = list(map(int, input().split()))

dp = [[-1] * (2000 + 1) for _ in range(n + 1)]

for i in range(m):
	print('yes') if rec(n, q[i]) == 1 else print('no')

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
A.sort()
q = int(input())
m = list(map(int,input().split()))

tar = max(max(m),sum(A))+1
dp = [[0]*tar for i in range(n+1)]
dp[0][0] = 1

for j in range(n):
    for k in range(tar):
        dp[j+1][k] = dp[j+1][k] or dp[j][k]

        if k >= A[j]:
            dp[j+1][k] = dp[j+1][k] or dp[j][k-A[j]]

for i in range(q):
    if dp[n][m[i]]:
        print("yes")
    else:
        print("no")

Solution (Python):
n = int(input())
A = [int(i) for i in input().split()]

q = int(input())
m = [int(i) for i in input().split()]

def dfs(idx, s, target):
    if s == target:
        return 1
    
    if s > target or idx == n:
        return 0
    if s + sum(A[idx:]) < target:
        return 0

    return dfs(idx+1, s, target) or dfs(idx+1, s + A[idx], target)

for target in m:
    ans = 'yes' if dfs(0, 0, target) else 'no'
    print(ans)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
Q = list(map(int, input().split()))
 
bits = 1
for a in A:
    bits |= bits << a
 
for q in Q:
    if bits >> q & 1:
        print("yes")
    else:
        print("no")

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
q = int(input())
m = list(map(int,input().split()))
flag = [0] * 2000
for i in range(2 ** len(a)):
         tmp = 0
         for j in range(len(a)):
                  if ((i >> j) & 1) == 1:
                           tmp += a[j]
         flag[tmp] = 1

for k in m:
         if flag[k] == 1:
                  print("yes")
         else:
                  print("no")

Solution (Python):



n = int(input())
A = list(map(int,input().split()))
a = len(A)
q = int(input())
m = list(map(int,input().split()))

Lis = set([])

for i in range(2**a):
    su = 0
    for j in range(n):
        if ((i >> j) & 1):
            su += A[j]
    Lis.add(su)

for i in m:
    if i in Lis:
        print("yes")
    else:
        print("no")

Solution (Python):
def main():
    n = int(input())
    n_lis = []
    n_lis= list(map(int, input().split()))
    q = int(input())
    q_lis = []
    sum_lis = []
    q_lis = list(map(int, input().split()))
    
    for i in range(2**n):
        test_lis = []
        for j in range(n):
            if ((i>>j) & 1):
                test_lis.append(n_lis[j])
        sumtest = sum(test_lis)
        sum_lis.append(sumtest)
    for qs in q_lis:
        if qs in sum_lis:
            print("yes")
        else:
            print("no")

if __name__ == "__main__":
    main()