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):



def check_solvable_recursively(number, is_solvable, candidate_numbers):
    """exhaustively search representable as summation of numbers in candidate_numbers

    Args:
        number: representable number
        is_solvable: is solvable list
        candidate_numbers: candidate numbers to be used

    Returns:
        None
    """
    if not is_solvable[number]:
        is_solvable[number] = True
    if candidate_numbers:
        check_solvable_recursively(number + candidate_numbers[0], is_solvable, candidate_numbers[1:])
        check_solvable_recursively(number, is_solvable, candidate_numbers[1:])


def main():
    raw_input()  
    candidate_numbers = [int(x) for x in raw_input().strip().split(' ')]
    raw_input()  
    target_number_list = [int(x) for x in raw_input().strip().split(' ')]

    is_solvable_list = [False] * 2001

    check_solvable_recursively(0, is_solvable_list, candidate_numbers)

    for target_number in target_number_list:
        if is_solvable_list[target_number]:
            print "yes"
        else:
            print "no"

if __name__ == "__main__":
    main()

Solution (Python):



def check_solvable_recursively(number, is_solvable, candidate_numbers):
    """exhaustively search representable as summation of numbers in candidate_numbers

    Args:
        number: representable number
        is_solvable: is solvable list
        candidate_numbers: candidate numbers to be used

    Returns:
        None
    """
    if not is_solvable[number]:
        is_solvable[number] = True
    if candidate_numbers:
        check_solvable_recursively(number + candidate_numbers[0], is_solvable, candidate_numbers[1:])
        check_solvable_recursively(number, is_solvable, candidate_numbers[1:])


def main():
    raw_input()  
    candidate_numbers = [int(x) for x in raw_input().strip().split(' ')]
    raw_input()  
    target_number_list = [int(x) for x in raw_input().strip().split(' ')]

    is_solvable_list = [False] * 2001

    check_solvable_recursively(0, is_solvable_list, candidate_numbers)

    for target_number in target_number_list:
        if is_solvable_list[target_number]:
            print "yes"
        else:
            print "no"

if __name__ == "__main__":
    main()

Solution (Python):



def main():
    raw_input()  
    candidate_number_list = [int(x) for x in raw_input().strip().split(' ')]
    raw_input()  
    target_number_list = [int(x) for x in raw_input().strip().split(' ')]

    representable_number_set = {0}
    for candidate_number in candidate_number_list:
        for num in representable_number_set.copy():
            representable_number_set.add(num + candidate_number)

    for target_number in target_number_list:
        if target_number in representable_number_set:
            print "yes"
        else:
            print "no"

if __name__ == "__main__":
    main()

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

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

def f(A, s, res):
  if res[0]:
    return
  if s == 0:
    res[0] = True
    return
  for i, a in enumerate(A):
    if a > s:
      break
    f(A[i+1:], s-a, res)

for mi in m:
  res = [False]

  if mi <= sumA:
    f(A, mi, res)

  if res[0]:
    print("yes")
  else:
    print("no")

Solution (Python):
n= int(input())
A = list(map(int, input().split()))
q = int(input())
Mi = map(int, input().split())
PS={}
def solve(i,m):
 if m == 0:
  return True
 if (i,m) in PS:
  return PS[(i,m)]
 if i >= n:
  return False
 res = solve(i+1, m) or solve(i + 1, m - A[i])
 PS[(i,m)] = res
 return res

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

Solution (Python):


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

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

for m in M:
    if m > sum_A:
        print('no')
    elif solve(0, m):
        print('yes')
    else:
        print('no')

Solution (Python):


def solve(i, m):
    global A
    if m == 0:
        ever_calc[i][m] = True
        return True
    elif m < 0:
        ever_calc[i][m] = False
        return False
    elif i == n:
        ever_calc[i][m] = False
        return False
    else:
        result = (solve(i+1, m) or solve(i+1, m-A[i]))
        ever_calc[i][m] = result
        return result

n = int(input())
A = tuple(map(int, input().split()))
q = int(input())
M = tuple(map(int, input().split()))
sum_A = sum(A)
ever_calc = [[None] * 2000 for i in range(n+1)]

for m in M:
    if m > sum_A:
        print('no')
    elif solve(0, m):
        print('yes')
    else:
        print('no')

Solution (Python):


def solve(i, m):
    global A
    if ever_calc[i][m] != None:
        return ever_calc[i][m]
    if m == 0:
        ever_calc[i][m] = True
        return True
    elif m < 0:
        ever_calc[i][m] = False
        return False
    elif i == n:
        ever_calc[i][m] = False
        return False
    else:
        result = (solve(i+1, m) or solve(i+1, m-A[i]))
        ever_calc[i][m] = result
        return result

n = int(input())
A = tuple(map(int, input().split()))
q = int(input())
M = tuple(map(int, input().split()))
sum_A = sum(A)
ever_calc = [[None] * 2000 for i in range(n+1)]

for m in M:
    if m > sum_A:
        print('no')
    elif solve(0, m):
        print('yes')
    else:
        print('no')

Solution (Python):
class MyClass():
    def main(self):
        self.n = input()
        self.A = map(int,raw_input().split())
        self.q = input()
        self.M = map(int,raw_input().split())
        
        W = map(self.solve,self.M)
        for w in W:
            print w

    def solve(self,m):
        w = self.rec(m,self.A)
        if w:
            return "yes"
        else:
            return "no"

    def rec(self,m,A):
        if len(A) == 1:
            r1 = False
        else:
            r1 = self.rec(m,A[1:])

        m_new = m - A[0]
        if m_new == 0:
            r2 = True
        elif len(A) > 1 and min(A[1:]) <= m_new <= sum(A[1:]):
            r2 = self.rec(m_new,A[1:])
        else:
            r2 = False

        if r1 or r2:
            return True
        else:
            return False

if __name__ == "__main__":
    MC = MyClass()
    MC.main()

Solution (Python):
from itertools import chain, combinations

def power_set(x):
	return chain.from_iterable(combinations(x, r) for r in range(len(x)+1))

def main():
	n = int(input())
	A = input()
	
	A = list(map(int, A.split()))
	q = int(input())
	m = input()
	ms = list(map(int, m.split()))
	powerset = power_set(A)
	sum_set = [sum(s) for s in powerset if len(s)!=0]
	
	for m in ms:
		if m in sum_set:
			print('yes')
		else:
			print('no')

if __name__ == '__main__':
	main()

Solution (Python):
def power_set(A, s):
	if len(A) == 0:
		return {s}
	else:
		return power_set(A[1:], s) | power_set(A[1:], s+A[0])

def main():
	n = int(input())
	A = input()
	
	A = list(map(int, A.split()))
	q = int(input())
	m = input()
	ms = list(map(int, m.split()))
	powerset = power_set(A, 0)
	
	for m in ms:
		if m in powerset:
			print('yes')
		else:
			print('no')

if __name__ == '__main__':
	main()

Solution (Python):
from collections import deque

def main():
    n = input()
    A = deque(map(int,raw_input().split()))
    q = input()
    M = map(int,raw_input().split())

    p = rec([0],A)

    for m in M:
        if m in p:
            print "yes"
        else:
            print "no"

def rec(a,A):
    if len(A) == 0:
        return a
    else:
        y = A.popleft()
        a = a+[x+y for x in a]
        return rec(a,A)

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
A = tuple(map(int,input().split()))
q = int(input())
Q = tuple(map(int, input().split()))
dp = [0]*(2**n)

for i in range(n):
    for j in range(1<<i):
        dp[j+(1<<i)] = dp[j] + A[i]

s = set(dp)
for n in Q:
    print("yes" if set([n]) & s else "no")

Solution (Python):
import bisect
n = int(input())
A = tuple(map(int,input().split()))
q = int(input())
Q = tuple(map(int, input().split()))
dp = [0]*(2**n)

for i in range(n):
    for j in range(1<<i):
        dp[j+(1<<i)] = dp[j] + A[i]
dp.sort()

for n in Q:
    i = bisect.bisect(dp, n)
    print("yes" if i>0 and n==dp[i-1] else "no")

Solution (Python):
import itertools


def rev(x):
    return sumA - x


if __name__ == "__main__":
    n = int(input())
    A = list(map(int, input().split()))
    q = int(input())
    M = list(map(int, input().split()))
    sumA = sum(A)
    all_sum = set()
    for i in range((n+1)//2):
        com = set(itertools.combinations(A, i+1))
        com_sum = set(map(sum, com))
        com_sum_rev = set(map(rev, com_sum))
        all_sum = all_sum.union(com_sum)
        all_sum = all_sum.union(com_sum_rev)
    for m in M:
        if m in all_sum:
            print("yes")
        else:
            print("no")

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

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

ans = []
s = sum(A)
for mm in m:
	if s < mm:
		ans.append('no')
	else:
		ans.append({True:'yes',False:'no'}[solve(0,mm)])

print('\n'.join(ans))

Solution (Python):


"""
????????????
?????? n ?????°??? A ??¨??´??° m ???????????????A ???????´?????????????????????????????´?????¶????????????????
m ???????????????????????????????????????????????°????????????????????????????????????
AA ??????????´???????????????????????????¨?????§????????????

??°??? A ??????????????????????????§???????????¨?????? q ?????? mi ????????????????????§???
???????????????????????? "yes" ????????? "no" ??¨???????????????????????????

n ??? 20 ; q ??? 200 ; 1 ??? A???????´? ??? 2000 ; 1 ??? Mi ??? 2000

"""

def main():
    """ ????????? """
    n = int(input())
    A = sorted(map(int,input().split()))
    q = int(input())
    M = list(map(int,input().split()))
    g = 0

    tA = []
    l = 2 ** n
    for i in range(1,l):
        c = 0
        bi = "{0:0{width}b}".format(i,width=n)
        bi = bi[::-1]
        for j in range(n):
            if bi[j] == "1":
                c += A[j]
        tA.append(c)


    for mi in M:
        if mi in tA:
            print("yes")
        else:
            print("no")

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
*A, = map(int, input().split())
q = int(input())
*Q, = map(int, input().split())

bits = 1
for a in A:
    bits |= bits << a

for q in Q:
    print("yes"*((bits >> q) & 1)or"no")

Solution (Python):
import sys
readline = sys.stdin.readline
readline()
bits = 1
for a in map(int, readline().split()): bits |= bits << a
readline()
sys.stdout.write("\n".join("yes"*((bits >> q) & 1)or"no" for q in map(int, readline().split())))
sys.stdout.write("\n")

Solution (Python):
input()
bits = 1
for a in map(int, input().split()): bits |= bits << a
input()
print(*("yes"*((bits >> q) & 1)or"no" for q in map(int, input().split())), sep='\n')

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

memo = {}
def solve(i, m):
    if m == 0:
        return True
    if i >= n:
        return False
    if memo.get((i, m), None) == None:
        memo[(i, m)] = solve(i + 1, m) or solve(i + 1, m - A[i])
    return memo[(i, m)]
for m in M:
    if solve(0, m):
        print('yes')
    else:
        print('no')

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














a = [0]
for i in range(n):
    a = a + [a[j] + data[i] for j in range(len(a))]

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

Solution (Python):

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

numbers = [0]

for a in A:
    numbers = numbers + [n+a for n in numbers]

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()))

sum_list = []
for i in range(2**n):
    b = '{0:0{1}b}'.format(i, n)

    temp = []
    for j in range(n):
        if b[j] == '1':
            temp.append(A[j])
    sum_list.append(sum(temp))

for k in m:
    print('yes' if k in sum_list else 'no')

Solution (Python):
from itertools import combinations

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

l = set(sum(t) for i in range(n) for t in combinations(A, i+1))

for j in m:
    print('yes' if j in l else 'no')

Solution (Python):
def abc(a,b,c):
    if a==n:
        pass
    else:
        if b == 1:
            c += A[a]
            s.add(c)
        abc(a+1,0,c)
        abc(a+1,1,c)

n = int(input())
A = [int(a) for a in input().split()]
q = int(input())
M = [int(m) for m in input().split()]
s = set()

abc(0,0,0)
abc(0,1,0)

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

Solution (Python):
from functools import lru_cache

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

@lru_cache(maxsize=None)
def solve(i, m):
    if m == 0:
        return True
    elif i >= n or m < A[i]:
        return False
    else:
        return solve(i + 1, m - A[i]) or solve(i + 1, m)

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

Solution (Python):
def solve(A, i, m, n):
    """Return if it is possible to make value m with some elements in A.
 
    n is length of A.
    i is index.
    R is the record of answer i, m.
    Using Divide-and-Conquer method.
    """
 
    if R[i][m] != None:
        return R[i][m]
    if m == 0:
        R[i][m] = True
        return True
    elif i >= n:
        R[i][m] = False
        return False
    else:
        ans = solve(A, i + 1, m, n) or solve(A, i + 1, m - A[i], n)
        R[i][m] = ans
        return ans
 
 
import sys
 
n = int(sys.stdin.readline())
A = tuple(map(int, sys.stdin.readline().split()))
q = int(sys.stdin.readline())
M = tuple(map(int, sys.stdin.readline().split()))
 
s_A = sum(A)
R = [[None] * 2000 for i in range(n + 1)]
 
ans = ''
 
for m in M:
    if s_A < m:
        ans += 'no\n'
    elif solve(A, 0, m, n):
        ans += 'yes\n'
    else:
        ans += 'no\n'
 
print(ans, end = '')

Solution (Python):


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


from itertools import combinations
x=[]
for i in range(len(A)):
    t=(list(combinations(A,i)))
    x.append(t)
combi=set()
for i in x:
    for j in i:
        combi.add(sum(j))

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

Solution (Python):
from functools import lru_cache

@lru_cache(maxsize = 10000)
def canProd(i,m):
     
    if m == 0:
        return True
    if i >= n:
        return False
 
    res = canProd(i+1,m) or canProd(i+1,m-a[i])
    return res
 
 
n = int(input())
a = [int(x) for x in input().split()]
q = int(input())
m = [int(x) for x in input().split()]
 
for i in m:
    if canProd(0,i):
        print("yes")
    else:
        print("no")

Solution (Python):
from functools import lru_cache

@lru_cache(maxsize = None)
def canProd(i,m):
     
    if m == 0:
        return True
    if i >= n:
        return False
 
    res = canProd(i+1,m) or canProd(i+1,m-a[i])
    return res
 
 
n = int(input())
a = [int(x) for x in input().split()]
q = int(input())
m = [int(x) for x in input().split()]

rs = [None]*2001

maxm = max(m)
minm = min(m)

for i in range(minm,maxm+1):
    if canProd(0,i):
        rs[i] = "yes"
    else:
        rs[i] = "no"

for i in m:
    print(rs[i])

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

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

for m_tmp in m:
    if sum(a) < m_tmp:
        print("no")
    elif solve(0, m_tmp):
        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 solve(i,m):
    if m == 0:
        return True
    if i >= n:
        return False
    res = solve(i+1,m) or solve(i+1,m-a[i])
    return res

for m_tmp in m:
    if sum(a) < m_tmp:
        print('no')
    elif solve(0,m_tmp):
        print('yes')
    else:
        print('no')

Solution (Python):
def ALDS1_5A():
    n, A, q = int(input()),list(map(int, input().split())), int(input())
    allFromA = [False]*2001
    for a in A:
        for i in range(2000-a, 0, -1):
            if allFromA[i]:
                allFromA[i+a] = True
        allFromA[a] = True

    for m in input().split():
        if allFromA[int(m)]:
            print('yes')
        else:
            print('no')

if __name__ == '__main__':
    ALDS1_5A()

Solution (Python):
n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))

record = [False] * 2001
for item in s:
    for i in range(2000 - item, 0, -1):
        if record[i]:
            record[i + item] = True
    record[item] = True

for m in t:
    if record[m]:
        print('yes')
    else:
        print('no')

Solution (Python):
a_len = int(input())
a_ar = sorted([int(n) for n in input().split(" ")])
b_len = int(input())
b_ar = [int(n) for n in input().split(" ")]
dp = [0 for n in range(2001)]
for a in a_ar:
    new_dp = dp[:]
    new_dp[a] = 1
    for i,d in enumerate(dp):
        if d and i + a <= 2000:
            new_dp[i + a] = 1
    dp = new_dp
for b in b_ar:
    if dp[b]:
        print("yes")
    else:
        print("no")

Solution (Python):
a_len = int(input())
a_ar = sorted([int(n) for n in input().split(" ")])
b_len = int(input())
b_ar = [int(n) for n in input().split(" ")]
dp = [0 for n in range(2001)]
for a in a_ar:
    new_dp = dp[:]
    new_dp[a] = 1
    for i,d in enumerate(dp):
        if d and i + a <= 2000:
            new_dp[i + a] = 1
        elif i + a > 2000:
            break
    dp = new_dp
for b in b_ar:
    if dp[b]:
        print("yes")
    else:
        print("no")

Solution (Python):
a_len = int(input())
a_ar = sorted([int(n) for n in input().split(" ")])
b_len = int(input())
b_ar = [int(n) for n in input().split(" ")]
max_b = max(b_ar)
dp = [0 for n in range(max_b + 1)]
for a in a_ar:
    new_dp = dp[:]
    new_dp[a] = 1
    for i,d in enumerate(dp):
        if d and i + a <= max_b:
            new_dp[i + a] = 1
    dp = new_dp
for b in b_ar:
    if dp[b]:
        print("yes")
    else:
        print("no")

Solution (Python):

import sys


def exhaustive(lst, size):
    result = []
    for i in range(0, 1 << size):
        total = 0
        for j in range(0, size):
            if (i & 0x01) == 1:
                total += lst[j]
            i = i >> 1
        result.append(total)
    return result


if __name__ == "__main__":
    lst = [val.split() for val in sys.stdin.read().splitlines()]
    n, data, m, targets = [[int(n) for n in inner_lst] for inner_lst in lst]
    result = exhaustive(data, int(n[0]))
    print("\n".join(["yes" if x in result else "no" for x in targets]))

Solution (Python):
def solve(i, m):
    if m == 0: return True

    if i < n and min(A[i:]) <= m <= sum(A[i:]):
        r1 = solve(i + 1, m-A[i])
        if r1: return r1
        r2 = solve(i + 1, m)
        if r2: return r2


n = int(raw_input())
A = map(int, raw_input().split())

q = int(raw_input())
M = map(int, raw_input().split())

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

Solution (Python):
def ALDS1_5A():
    n, A, q = int(input()), list(map(int, input().split())), int(input())
    S=[False for i in range(2001)]
    for a in A:
        for i in range(2001-a, 0, -1):
            if S[i]: S[i+a] = True
        S[a] = True
    for mi in input().split():
        if S[int(mi)]:
            print('yes')
        else:
            print('no')

if __name__ == '__main__':
    ALDS1_5A()

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

add_result = [0]*2001
for i in a:
	for j in range(2000, -1, -1):
		if add_result[j] == 1:
			add_result[i+j] = 1
			
	add_result[i] = 1
	

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

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
q = int(input())
mi = map(int, input().split())
t = {}

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

for m in mi:
    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()))

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

for tmp_m in m:
  if sum(A) < tmp_m:
    print('no')
  elif solve(0, tmp_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()))

table = [[-1 for i in range(max(M)+1)] for j in range(n)]

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

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

Solution (Python):
from itertools import product


def main():
    """
    2^20 = 1,048,576
    q = 200
    200,000,000
    limit 5s ???????????????OK
    """
    n = int(input())
    A = list(map(int, input().split()))
    q = int(input())
    M = map(int, input().split())

    dp(n, A, q, M)


def combination(n, A, q, M):
    for m in M:
        if m == 0 or solve(m, A, n):
            print("yes")
        else:
            print("no")


def dp(n, A, q, M):
    M_max = 2000
    _dp = [False] * (M_max + 1)
    for a in A:
        
        for i in range(M_max, 0, -1):
            if _dp[i] and i + a <= M_max:
                _dp[i + a] = True
        
        _dp[a] = True

    for m in M:
        if _dp[m]:
            print("yes")
        else:
            print("no")


def solve(m, A, n):
    
    for b in product([0, 1], repeat=n):
        s = sum(a * bit for a, bit in zip(A, b))
        if m == s:
            return True

    return False


def f1(n):
    for i in range(2 ** n):
        
        
        bit = bin(i)[2:]
        yield map(int, bit.zfill(n))

if __name__ == '__main__':
    main()

Solution (Python):
from itertools import combinations
n = int(input())
A = tuple(map(int, input().split()))
B = set(A)
for i in range(2, n + 1):
    for C in combinations(A, i):
        B.add(sum(C))
q = int(input())
for m in map(int, input().split()):
    print("yes" if m in B else "no")

Solution (Python):
n = int(input())
SET1 = {0}
for a in map(int, input().split()):
    for b in tuple(SET1):
        SET1.add(a + b)
input()
for m in map(int, input().split()):
    print('yes' if m in SET1 else 'no')

Solution (Python):



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(" ")]

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

    ans = []
    for m in M:
        if solve(0, m):
            ans.append("yes")
        else:
            ans.append("no")

    print("\n".join(ans))

Solution (Python):
A_count = int(input());
A = [int(n) for n in input().split()];
M_count = int(input());
M = [int(n) for n in input().split()];

memo = [[None for i in range(2000)] for j in range(A_count + 1)];

def solve(start, target):
    if memo[start][target] is not None:
        return memo[start][target];
    if target == 0:
        return True;
    elif start >= A_count:
        return False;
    else:
        result = solve(start + 1, target) or solve(start + 1, target - A[start]);
        if result:
            memo[start][target] = True;
            return True;
        else:
            memo[start][target] = False;
            return False;

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

Solution (Python):
a = []
d = {}

def decode():
    global a

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

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

    return n, a, q, ms


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

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

    if a[i] == m:
        d[(i, m)] = True
        return True
    else:
        if i < len(a) - 1:

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

        else:
            d[(i, m)] = False
            return False


if __name__ == '__main__':

    n, a, q, ms = decode()
    for m in ms:
        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(' ')))

dp = {}


def solve(p, t):
  if ((p, t) in dp):
    return dp[(p, t)]

  if (p == n):
    
    return t == 0

  
  ans = solve(p+1, t-A[p]) or solve(p+1, t)
  dp[(p, t)] = ans
  return ans

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

Solution (Python):
num_n = int(input())
n = [int(x) for x in input().split()]
num_m = int(input())
m = [int(x) for x in input().split()]
     
def solve(i, m):
   if m == 0:
      return True
   if i >= num_n or m > sum(n):
      return False
   res = solve(i + 1, m) or solve(i + 1,m - n[i])
   return res
      
for k in range(num_m):
   if solve(0, m[k]):
      print ("yes")
   else:
      print ("no")

Solution (Python):
_ = int(input())
hoge = [int(x) for x in input().split()]
_ = int(input())

def exSearch(i, m):
    if m == 0:
        return True
    if i >= len(hoge) or m > sum(hoge):
        return False
    res = exSearch(i+1, m) or exSearch(i+1, m-hoge[i])
    return res

if __name__ == '__main__':
    
    for val in (int(x) for x in input().split()):
        if exSearch(0, val):
            print ('yes')
        else:
            print ('no')

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
r=[]
def f(s,k):
    if k>=0:
        global r
        r+=[s]
        f(s+A[k-1],k-1)
        f(s,k-1)
f(0,n)
input()
for e in map(int,input().split()):print(['no','yes'][e in r])

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
r=[]
def f(s,k):
    if k>=0:
        global r
        r+=[s]
        f(s+A[k-1],k-1)
        f(s,k-1)
f(0,n)
input()
for e in map(int,input().split()):print(['no','yes'][e in r])

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
r=[]
def f(s,k):
    if k>=0:
        global r
        r+=[s]
        f(s+A[k-1],k-1)
        f(s,k-1)
f(0,n)
input()
for e in map(int,input().split()):print(['no','yes'][e in r])

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
r=[]
def f(s,k):
    if k>=0:
        global r
        r+=[s]
        f(s+A[k-1],k-1)
        f(s,k-1)
f(0,n)
input()
for e in map(int,input().split()):print(['no','yes'][e in r])

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
r=set()
def f(s,k):
    if k>=0:
        global r
        r.add(s)
        f(s+A[k-1],k-1)
        f(s,k-1)
f(0,n)
input()
for e in map(int,input().split()):print(['no','yes'][e in r])

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
r=set()
def f(s,k):
    if k>=0:
        global r
        r.add(s)
        f(s+A[k-1],k-1)
        f(s,k-1)
f(0,n)
input()
for e in map(int,input().split()):print(['no','yes'][e in r])

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
r=set()
def f(s,k):
    if k>=0:
        global r
        r.add(s)
        f(s+A[k-1],k-1)
        f(s,k-1)
f(0,n)
input()
for e in map(int,input().split()):print(['no','yes'][e in r])

Solution (Python):
input()
s = {0}
for a in map(int,input().split()):
    for b in list(s):
        s.add(a+b)
input()
for e in map(int,input().split()):
    print('yes' if e in s else 'no')

Solution (Python):
input()
s={0}
for a in map(int,input().split()):
 for b in list(s):s.add(a+b)
input()
for e in map(int,input().split()):print(['no','yes'][e in s])

Solution (Python):
input()
s={0}
for a in map(int,input().split()):
 for b in list(s):s.add(a+b)
input()
for e in input().split():print(['no','yes'][int(e)in s])

Solution (Python):
input()
s={0}
for a in map(int,input().split()):
 for b in list(s):s.add(a+b)
input()
for e in input().split():print(['no','yes'][int(e)in s])

Solution (Python):
b=1
input()
for a in map(int,input().split()):b|=b<<a
input()
for m in map(int,input().split()):print(['no','yes'][(b>>m)&1])

Solution (Python):
b=1
input()
for a in map(int,input().split()):b|=b<<a
input()
for m in map(int,input().split()):print(['no','yes'][(b>>m)&1])

Solution (Python):



def solve(p, t, A, result):
    if A[p] == t:
        result[(p,t)] = True
        return True
    if p == len(A) - 1:
        return False
    if (p,t) in result:
        
        return result[(p,t)]
    if solve(p+1, t-A[p], A, result):
        result[(p,t)] = True
        return True
    if solve(p+1, t, A, result):
        result[(p,t)] = True
        return True
    result[(p,t)] = False 
    return False

import sys

n = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
num_q = int(sys.stdin.readline())
query = list(map(int, sys.stdin.readline().split()))
result = dict()

for m in query:
    if solve(0, m, A, result):
        print('yes')
    else:
        print('no')