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 Mi.

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 (Mi) are given.

Output

For each question Mi, print yes or no.

Constraints

n ≤ 20

 q ≤ 200 

1 ≤ elements in A ≤ 2000

1 ≤ Mi ≤ 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].

Template in C
-->



Sample input:
5
1 5 7 10 21
8
2 4 17 8 22 21 100 35


Sample output:
no
no
yes
yes
yes
yes
no
no

Submission status: Wrong Answer

Solution code:
cnt = 0
def merge(array):
    global cnt
    mid = (len(array))
    if mid > 1:
        left = merge(array[:(int)(mid/2)])
        right = merge(array[(int)(mid/2):])
        array = []
        while len(left) != 0 and len(right) != 0:
            if left[0] < right[0]:
                array.append(left.pop(0))
                cnt += 1
            else:
                array.append(right.pop(0))
                cnt += 1
        if len(left) != 0:
            cnt += len(left)
            array.extend(left)
        elif len(right) != 0:
            cnt += len(right)
            array.extend(right)
    return array

input()

l = merge(list(map(int,input().split())))
print(*l)
print(cnt)

Submission status: Wrong Answer

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

def exhastive_search(target, head, sum):
    for i in range(head, N):
        sum += A[i]
        print(sum)
        if target == sum:
            return True
        elif target > sum:
            if exhastive_search(target, i+1, sum):
                return True
        else:
            return False
        sum -= A[i]
    return False


for target in M:
    print(target,"---------------")
    head = 0
    sum = 0
    result = "no"
    for i in range(N):
        if exhastive_search(target, i, sum):
            result = "yes"
            break
    print(result)

Submission status: Wrong Answer

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

def exhastive_search(target, head, sum):
    for i in range(head, N):
        sum += A[i]
        if target == sum:
            return True
        elif target > sum:
            if exhastive_search(target, i+1, sum):
                return True
        else:
            return False
        sum -= A[i]
    return False


for target in M:
    sum = 0
    result = "no"
    for i in range(N):
        if exhastive_search(target, i, sum):
            result = "yes"
            break
    print(result)

Submission status: Wrong Answer

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

def exhastive_search(target, head, sum):
    for i in range(head, N):
        sum += A[i]
        if target == sum:
            return True
        elif target > sum:
            if exhastive_search(target, i+1, sum):
                return True
            return False
        else:
            return False
    return False


for target in M:
    head = 0
    sum = 0
    result = "no"
    if exhastive_search(target, head, sum):
        result = "yes"
        break
    print(result)

Submission status: Wrong Answer

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

exhaustive_dict = {}

def create_exhastive_list(head, sum):
    for i in range(head, N):
        sum += A[i]
        print(sum)
        exhaustive_dict[sum] = 1
        create_exhastive_list(i+1, sum)
        sum -= A[i]

head = 0
sum = 0
create_exhastive_list(head, sum)
print(exhaustive_dict)


for target in M:
    if target in exhaustive_dict.keys():
        print("yes")
    else:
        print("no")

Submission status: Wrong Answer

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

exhaustive_dict = {}

def create_exhastive_list(head, sum):
    for i in range(head, N):
        sum += A[i]
        exhaustive_dict[sum] = 1
        create_exhastive_list(i+1, sum)
        sum -= A[i]

head = 0
sum = 0
create_exhastive_list(head, sum)
print(exhaustive_dict)


for target in M:
    if target in exhaustive_dict.keys():
        print("yes")
    else:
        print("no")

Submission status: Wrong Answer

Solution code:
# -*- coding=utf-8 -*-
import itertools

count = int(input())
_list = list(map(int, input().split(" ")))

count2 = int(input())
_answers = list(map(int, input().split(" ")))

desc = []

# answersの数だけloopして取ってくる
for answer in _answers:
    tmp = [i for i in _list if answer >= i]

    # そもそもtmpの中身をsumしてanswer未満ならば強制的にno
    if answer > sum(tmp):
        desc.append("no")

    # itertoolsのコンビネーションを使用して解く
    else:
        for i in range(len(tmp)):
            tmp2 = list(itertools.combinations(tmp, i))
            for tmp3 in tmp2:
                if sum(tmp3) == answer:
                    desc.append("yes")
                    break

print(desc)

Submission status: Wrong Answer

Solution code:
# -*- coding=utf-8 -*-
import itertools

count = int(input())
_list = list(map(int, input().split(" ")))

count2 = int(input())
_answers = list(map(int, input().split(" ")))

desc = []
checked = False

# answersの数だけloopして取ってくる
for answer in _answers:
    checked = False
    tmp = [i for i in _list if answer >= i]

    # そもそもtmpの中身をsumしてanswer未満ならば強制的にno
    if answer > sum(tmp):
        print(answer)
        desc.append("no")

    # itertoolsのコンビネーションを使用して解く
    else:
        for i in range(len(tmp) + 1):
            if checked == True:
                break

            tmp2 = list(itertools.combinations(tmp, i))
            for tmp3 in tmp2:
                if sum(tmp3) == answer:
                    print(answer)
                    desc.append("yes")
                    checked = True
                    break

        if checked != True:
            desc.append("no")

print(desc)

Submission status: Wrong Answer

Solution code:
def can_construct_q(q, array, i, sum_sofar):
    if sum_sofar == q or sum_sofar + array[i] == q:
        return True
    elif sum_sofar > q or i >= len(array) - 1:
        return False
    if can_construct_q(q, array, i + 1, sum_sofar + array[i]):
        return True
    if can_construct_q(q, array, i + 1, sum_sofar):
        return True


def main():
    input()
    array_a = list(map(int, input().split()))
    input()
    array_q = map(int, input().split())
    for q in array_q:
        print(q)
        if can_construct_q(q, array_a, 0, 0):
            print('yes')
        else:
            print('no')
    return


main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

"""
全探索
・再帰で作る
"""

N = int(input())
aN = list(map(int, input().split()))
Q = int(input())
mQ = list(map(int, input().split()))

def dfs(cur, depth, ans):
    # 終了条件
    if cur == ans:
        return True
    # 全探索
    for i in range(depth, N):
        if dfs(cur+aN[i], depth+i+1, ans):
            return True
    # 見つからなかった
    return False

for i in range(Q):
    if dfs(0, 0, mQ[i]):
        print('yes')
    else:
        print('no')

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
b = int(input())
c = list(map(int, input().split()))
e = []
for i in range(2**n):
    d = []
    for j in range(n):
        if (i>>j)&1:
            d.append(a[j])
            e.append(sum(d))
for k in c:
    if c in e:
        print("yes")
    else:
        print("no")

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
A = map(int,raw_input().split())
q = int(raw_input())
mi = map(int,raw_input().split())

for m in mi:
    if m < min(A):
        print 'no'
        continue
    try:
        for k in range(len(A)-1):
            for j in range(k+1,len(A)):
                tmp = A[k] + A[j]
                if m == tmp:
                    raise Exception
        else:
            print 'no'
    except Exception:
        print 'yes'
        continue

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
A = map(int,raw_input().split())
q = int(raw_input())
mi = map(int,raw_input().split())

S = []
for k in range(1,2**len(A)):
    S.append(map(int,list((format(k,'b').zfill(5)))))

for m in mi:
    for k in range(len(S)):
        tot = 0
        for j in range(len(S[k])):
            if S[k][j]:
                tot += A[j]
        if m == tot:
            print 'yes'
            break
    else:
        print 'no'

Submission status: Wrong Answer

Solution code:
for i in range( 0, 3 ):
	print( "yes" )

Submission status: Wrong Answer

Solution code:
d = int( input() )
for i in range( 0, 3 ):
	print( "yes" )

Submission status: Wrong Answer

Solution code:
for i in range( 0, 5 ):
	print( "yes" )

Submission status: Wrong Answer

Solution code:
d = int( input() )
for i in range( 0, 5 ):
	print( "yes" )

Submission status: Wrong Answer

Solution code:
a = int( input() )
A = [ int( val ) for val in input().split( ' ' ) ]
d = int( input() )
for i in range( 0, 5 ):
	print( "yes" )

Submission status: Wrong Answer

Solution code:
n = int( input() )
A = [ int( val ) for val in input().split( ' ' ) ]
q = int( input() )
for i in range( 0, q ):
	print( "yes" )

Submission status: Wrong Answer

Solution code:
import sys
n = int( sys.stdin.readline( ) )
A = [ int( val ) for val in input( ).rstrip( ).split( " " ) ]
q = int( sys.stdin.readline( ) )
M = [ int( val ) for val in input( ).rstrip( ).split( " " ) ]
for i in range( 0, q ):
	print( "yes" )

Submission status: Wrong Answer

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

global n
n = int(input())
st = input()
A = list(map(int,st.split()))
# dont use q(num of ans patarn) dumping!
input()
st = input()
ans = list(map(int,st.split()))

for x in ans:
    if(solve(0,x,A) == True):
        print('yes')
    else:
        print('no')

Submission status: Wrong Answer

Solution code:
n, a, q, ms = int(input()), list(map(int, input().split())), input(), map(int, input().split())

cache = {}


def sum_a(tmp, bin, i=0, mask=1):
    global a
    if not bin:
        return tmp
    elif bin in cache:
        return cache[bin]
    elif bin & mask:
        tmp += a[i]
    result = sum_a(tmp, bin & ~mask, i + 1, mask << 1)
    cache[bin] = result
    return result


for m in ms:
    for bin in range(1, 2 ** n - 1):
        if sum_a(0, bin) == m:
            print('yes')
            break
    else:
        print('no')

Submission status: Wrong Answer

Solution code:
from itertools import combinations

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

for m in map(int, input().split()):
    print('yes' if m in set(sum(t) for i in range(n) for t in combinations(a, i + 1)) else 'no')

Submission status: Wrong Answer

Solution code:
n = input()

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

q = input()

m = map(int, raw_input().split())

for i in range(q):
  for j in range(n):
    if A[-j] < m[i]:
      m[i] = m[i] - A[-j]
    if m[i] <= 0:
      break
  if m[i] == 0:
    print "yes"
  else:
    print "no"

Submission status: Wrong Answer

Solution code:
n = input()

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

q = input()

m = map(int, raw_input().split())

for i in range(q):
  for j in range(n):
    if A[-j] <= m[i]:
      m[i] = m[i] - A[-j]
    if m[i] <= 0:
      break
  if m[i] == 0:
    print "yes"
  else:
    print "no"

Submission status: Wrong Answer

Solution code:
n = input()

A = {}
A = map(int, raw_input().split())
 
q = input()
 
m = map(int, raw_input().split())

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


for i in range(q):
  for j in range(n):
    if A[-j] <= m[i]:
      m[i] = m[i] - A[-j]
    if m[i] <= 0:
      break
  if m[i] == 0:
    print "yes"
  else:
    print "no"

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
A = map(int, raw_input().split())
q = int(raw_input())
m = map(int, raw_input().split())

def ES_m(i):
    sum = 0
    frag = [0]*n
    frag2 = 0
    for j in range(0, n):
        if A[j] > m[i]:
            frag[j] == 1
        elif A[j] == m[i]:
            frag2 = 1
            break
    for j in range(0, n):
        if frag[j] == 0:
            sum = A[j]
            for k in range(j+1, n):
                    if frag[k] == 0:
                        sum += A[k]
                    if sum > m[i]:
                        sum -= A[k]
                        frag[k] = 1
                    elif sum == m[i]:
                        frag2 = 1
                        break
    if frag2 == 1:
        print "yes"
    else:
        print "no"

for i in range(0, q):
	ES_m(i)

Submission status: Wrong Answer

Solution code:
def check(m,g,A,n):
    
    for i in range(n):
        gg = g + A[n-i-1]
        if m == gg:
            return True
        elif n == 0 or m < gg:
            continue
        if check(m,gg,A,n-i-1) == True:
            return True
    return False
        

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

mini = min(A)
nor = sum(A)

for mi in m:
    if mi < mini or mi > nor:
        print("no")
    if check(mi,0,A,n):
        print("yes")
    else:
        print("no")

Submission status: Wrong Answer

Solution code:
def check(m,g,A,n):
    
    for i in range(n):
        gg = g + A[n-i-1]
        if m == gg:
            return True
        elif n == 0 or m < gg:
            continue
        if check(m,gg,A,n-i-1) == True:
            return True
    return False
        

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

n=5
A=[1, 5, 7, 10, 21]
q=10
m=[2, 4, 6, 15, 17, 8, 22, 21, 100, 35]


mini = min(A)
nor = sum(A)

for mi in m:
    if mi < mini or mi > nor:
        print("no")
        continue
    if check(mi,0,A,n):
        print("yes")
    else:
        print("no")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
q = int(input())
m = [int(i) for i in input().split()]
    
def zentansaku(j,k,l):  # ??????A[???]???????????? A[j]???A[l?????????A[N??????] ?????§????¶????????????????
     num = 0
     for i in range(l,N-1):
         Z = j + A[i]
         
         if Z == k:
             return True
         else :
             if j+1 == N :
                 return False
             else :
                 zentansaku(Z,k,l+1)
         num += 1        
                

for i in range(q):
    check = 0
    for i2 in range(N-1):
        if zentansaku(A[i2],m[i],i2+1) == True:
            print("yes")
            check = 1
    if check == 0 :
        print("no")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
q = int(input())
m = [int(i) for i in input().split()]
    
def zentansaku(j,k,l):  # ??????A[???]???????????? A[j]???A[l?????????A[N??????] ?????§????¶????????????????
     num = 0
     for i in range(l,N):
         Z = j + A[i]
         
         if Z == k:
             return True
         else :
             if j+1 == N :
                 return False
             else :
                 zentansaku(Z,k,l+1)
         num += 1        
                

for i in range(q):
    check = 0
    for i2 in range(N):
        if zentansaku(A[i2],m[i],i2+1) == True:
            print("yes")
            check = 1
    if check == 0 :
        print("no")

Submission status: Wrong Answer

Solution code:

N = int(input())
A = [int(i) for i in input().split()]
q = int(input())
m = [int(i) for i in input().split()]
    
def zentansaku(j,k,l):  # ??????A[???]???????????? A[j]???A[l?????????A[N??????] ?????§????¶????????????????
     num = 0
     
     if j == k :
         return True
         
     for i in range(l,N):
         Z = j + A[i]
         
         if Z == k:
             return True
         else :
             if j+1 == N :
                 return False
             else :
                 zentansaku(Z,k,l+1)
         num += 1        
                

for i in range(q):
    check = 0
    for i2 in range(N):
        if zentansaku(A[i2],m[i],i2+1) == True:
            print("yes")
            check = 1
    if check == 0 :
        print("no")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
q = int(input())
m = [int(i) for i in input().split()]
    
def zentansaku(j,k,l):  # ??????A[???]???????????? A[j]???A[l?????????A[N??????] ?????§????¶????????????????
     
     if j == k :
         return True
         
     for i in range(l,N):
         Z = j + A[i]
         
         if Z == k:
             return True
         else :
             if j+1 == N :
                 return False
             else :
                 zentansaku(Z,k,l+1)
          
                

for i in range(q):
    check = 0
    for i2 in range(N):
        if check == 1 :
            break    #??????yes?????????????????°break??????
        if zentansaku(A[i2],m[i],i2+1) == True:
            print("yes")
            check = 1
    if check == 0 :
        print("no")

Submission status: Wrong Answer

Solution code:

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

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

result = []
for i in range(q):
    result.append('no')

for i in range(n-1):
    sum_n = A[i]
    for j in range(n-1-i):
        ad = A[i+1+j]
        for k in range(n-2-i-j):
            sum_n = sum_n + ad
            ad = ad + A[i+j+2+k]
            for l in range(q):
                if M[l] == sum_n:
                    result[l] = 'yes'

for i in result:
    print(i)

Submission status: Wrong Answer

Solution code:

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

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

result = []
for i in range(q):
    result.append('no')

for i in range(n-1):
    for j in range(n-1-i):
        sum_n = A[i] 
        ad = A[i+1+j]
        for k in range(n-2-i-j):
            sum_n = sum_n + ad
            ad = ad + A[i+j+2+k]
            for l in range(q):
                if M[l] == sum_n:
                    result[l] = 'yes'

for i in result:
    print(i)

Submission status: Wrong Answer

Solution code:

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

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

result = []
for i in range(q):
    result.append('no')

for i in range(n):
    sum_n = A[i]
    for j in range(q):
        if M[j] == sum_n:
            result[j] = 'yes'
    for j in range(n-1-i):
        sum_n = A[i]
        ad = A[i+j+1]
        sum_n = sum_n + ad
        for k in range(q):
            if M[k] == sum_n:
                result[k] = 'yes'
        for k in range(n-2-i-j):
            ad = ad + A[i+j+2+k]
            sum_n = sum_n + ad
            for l in range(q):
                if M[l] == sum_n:
                    result[l] = 'yes'

for i in result:
    print(i)

Submission status: Wrong Answer

Solution code:

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

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

result = []
for i in range(q):
    result.append('no')

for i in range(n):
    sum_n = A[i]
    for j in range(q):
        if M[j] == sum_n:
            result[j] = 'yes'
    for j in range(n-1-i):
        sum_n = A[i]
        ad = A[i+j+1]
        sum_n = sum_n + ad
        for k in range(q):
            if M[k] == sum_n:
                result[k] = 'yes'
        for k in range(n-2-i-j):
            ad = ad + A[i+j+2+k]
            sum_n = A[i] + ad
            for l in range(q):
                if M[l] == sum_n:
                    result[l] = 'yes'

for i in result:
    print(i)

Submission status: Wrong Answer

Solution code:

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

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

result = []
for i in range(q):
    result.append('no')

for i in range(n):
    sum_n = A[i]
    for j in range(q):
        if M[j] == sum_n:
            result[j] = 'yes'
    for j in range(n-1-i):
        sum_n = A[i]
        ad = A[i+j+1]
        sum_n = sum_n + ad
        for k in range(q):
            if M[k] == sum_n:
                result[k] = 'yes'
        for k in range(n-2-i-j):
            sum_n = A[i]
            ad = ad + A[i+j+2+k]
            sum_n = sum_n + ad
            for l in range(q):
                if M[l] == sum_n:
                    result[l] = 'yes'

for i in result:
    print(i)

Submission status: Wrong Answer

Solution code:

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

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

result = []
for i in range(q):
    result.append('no')

for i in range(n):
    sum_n = A[i]
    for j in range(q):
        if M[j] == sum_n:
            result[j] = 'yes'
    for j in range(n-1-i):
        sum_n = A[i]
        ad = A[i+j+1]
        sum_n = sum_n + ad
        for k in range(q):
            if M[k] == sum_n:
                result[k] = 'yes'
        for k in range(n-2-i-j):
            ad = A[i+j+2+k]
            sum_n = sum_n + ad
            for l in range(q):
                if M[l] == sum_n:
                    result[l] = 'yes'

for i in result:
    print(i)

Submission status: Wrong Answer

Solution code:
n = input('n : ')
A = map(int, raw_input('A : ').split())
q = input('q : ')
m = map(int, raw_input('m : ').split())

a = [[0 for j in range(max(m) + 1)] for i in range(n)]

for i in range(n):
    for j in range(max(m) + 1):
        if (i == 0):
            temp = A[i]
            if (temp <= j):
                a[i][j] = temp
            else:
                a[i][j] = 0
        else:
            temp1 = 0
            temp2 = 0
            if (j - A[i] >= 0):
                temp1 = a[i-1][j - A[i]] + A[i]
            temp2 = a[i-1][j]
            a[i][j] = max(temp1, temp2)

ans = []

for i in range(q):
    ans.append(a[n-1][m[i]] == m[i])

print str(ans)

Submission status: Wrong Answer

Solution code:
n = input('n : ')
A = map(int, raw_input('A : ').split())
q = input('q : ')
m = map(int, raw_input('m : ').split())

a = [[0 for j in range(max(m) + 1)] for i in range(n)]

for i in range(n):
    for j in range(max(m) + 1):
        if (i == 0):
            temp = A[i]
            if (temp <= j):
                a[i][j] = temp
            else:
                a[i][j] = 0
        else:
            temp1 = 0
            temp2 = 0
            if (j - A[i] >= 0):
                temp1 = a[i-1][j - A[i]] + A[i]
            temp2 = a[i-1][j]
            a[i][j] = max(temp1, temp2)

ans = []

for i in range(q):
    if (a[n-1][m[i]] == m[i]):
        ans.append("yes")
    else:
        ans.append("no")

print ans

Submission status: Wrong Answer

Solution code:
n = input('n : ')
A = map(int, raw_input('A : ').split())
q = input('q : ')
m = map(int, raw_input('m : ').split())

a = [[0 for j in range(max(m) + 1)] for i in range(n)]

for i in range(n):
    for j in range(max(m) + 1):
        if (i == 0):
            temp = A[i]
            if (temp <= j):
                a[i][j] = temp
            else:
                a[i][j] = 0
        else:
            temp1 = 0
            temp2 = 0
            if (j - A[i] >= 0):
                temp1 = a[i-1][j - A[i]] + A[i]
            temp2 = a[i-1][j]
            a[i][j] = max(temp1, temp2)

ans = []

for i in range(q):
    if (a[n-1][m[i]] == m[i]):
        ans.append("yes")
    else:
        ans.append("no")

for i in ans:
    print i

Submission status: Wrong Answer

Solution code:
n = input( "a")
A = map(int, raw_input().split())
q = input()
m = map(int, raw_input().split())

a = [[0 for j in range(max(m) + 1)] for i in range(n)]

for i in range(n):
    for j in range(max(m) + 1):
        if (i == 0):
            temp = A[i]
            if (temp <= j):
                a[i][j] = temp
            else:
                a[i][j] = 0
        else:
            temp1 = 0
            temp2 = 0
            if (j - A[i] >= 0):
                temp1 = a[i-1][j - A[i]] + A[i]
            temp2 = a[i-1][j]
            a[i][j] = max(temp1, temp2)

for i in range(q):
    if (a[n-1][m[i]] == m[i]):
        print "yes"
    else:
        print "no"

Submission status: Wrong Answer

Solution code:

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

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

result = []
for i in range(q):
    result.append('no')

def adder(axis = 0, nums = [0], M = [0], q = 0):
    for i in range(q):
        if M[i] == axis:
            result[i] = 'yes'
            break
    length = len(nums)
    if length != 0:
        for i in range(length):
            sum_n = axis + nums[i]
            adder(sum_n, nums[i+1:], M, q)

for i in range(n-1):
    adder(A[i], A[i+1:], M, q)

for i in result:
    print(i)

Submission status: Wrong Answer

Solution code:

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

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

result = []
for i in range(q):
    result.append('no')

def adder(axis = 0, nums = [0], M = [0], q = 0):
    for i in range(q):
        if M[i] == axis:
            result[i] = 'yes'
            break
    length = len(nums)
    if length != 0:
        for i in range(length):
            sum_n = axis + nums[i]
            adder(sum_n, nums[i+1:], M, q)

for i in range(n):
    adder(A[i], A[i+1:], M, q)

for i in result:
    print(i)

Submission status: Wrong Answer

Solution code:
n = input()
A = map( int , raw_input().split() )
q = input()
mi = map( int , raw_input().split() )

def solve(i, m):
  if m == 0:
    return True
  elif i >= n or sum(A):
    return False

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

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

Submission status: Wrong Answer

Solution code:
n = input()
A = map( int , raw_input().split() )
q = input()
mi = map( int , raw_input().split() )

def solve(i, m):
  if m == 0:
    return True
  if i >= n or sum(A):
    return False

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

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

Submission status: Wrong Answer

Solution code:
n = input()
A = map( int , raw_input().split() )
q = input()
mi = map( int , raw_input().split() )

def solve(i, m):
  if m == 0:
    return True
  elif i >= n or sum(A):
    return False

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

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

Submission status: Wrong Answer

Solution code:
n = input()
A = map(int,raw_input().split())
Q = input()
m = map(int,raw_input().split())

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

  for j in m:
    if s(0, m) == True:
      print"yes"
    else:
      print"no"

Submission status: Wrong Answer

Solution code:
n = input()
A = map(int,raw_input().split())
Q = input()
m = map(int,raw_input().split())

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

  for j in m:
    if s(0, m) == True:
      print "yes"
    else:
      print "no"

Submission status: Wrong Answer

Solution code:
n = input()
A = map(int,raw_input().split())
Q = input()
m = map(int,raw_input().split())

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

  for j in Q:
    if s(0, m) == True:
      print"yes"
    else:
      print"no"

Submission status: Wrong Answer

Solution code:
n = input()
A = map(int,raw_input().split())
Q = input()
m = map(int,raw_input().split())

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

  for j in range(Q):
    if s(0, m) == True:
      print "yes"
    else:
      print "no"

Submission status: Wrong Answer

Solution code:
n = input()
A = map(int,raw_input().split())
Q = input()
m = map(int,raw_input().split())

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

  for j in range(Q):
    if s(0, m[j]) == True:
      print "yes"
    else:
      print "no"

Submission status: Wrong Answer

Solution code:
n = input()
A = map(int,raw_input().split())
Q = input()
m = map(int,raw_input().split())

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

  for j in range(Q):
    if s(0, m[j]):
      print "yes"
    else:
      print "no"

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
A = map(int,raw_input().split())
Q = int(raw_input())
m = map(int,raw_input().split())

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

  for j in range(Q):
    if s(0, m[j]) == True:
      print "yes"
    else:
      print "no"

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
A = map(int,raw_input().split())
Q = int(raw_input())
m = map(int,raw_input().split())

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

  for j in range(Q):
    if s(0, m[j]):
      print "yes"
    else:
      print "no"

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
A = map(int,raw_input().split())
Q = int(raw_input())
m = map(int,raw_input().split())

def s(i, m):
  if m == 0:
    return 1
  if i >= n or m > sum(A):
    return 0
  r = s(i + 1, m) or s(i + 1, m) or s(i + 1, m - A[i])
  return r

  for j in range(Q):
    if s(0, m[j]):
      print "yes"
    else:
      print "no"

Submission status: Wrong Answer

Solution code:
n = int(raw_input())
A = map(int,raw_input().split())
Q = int(raw_input())
m = map(int,raw_input().split())

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

  for j in range(Q):
    if s(0, m[j]):
      print "yes"
    else:
      print "no"

Submission status: Wrong Answer

Solution code:
def solve(i, j):
    if i == 0:
    	return True
    if j < n and A[0] <= i <= sum(A[j:]):
        x = solve(i-A[j], j+1)
        if x:
        	return x
        y = solve(i, j+1)
        if y:
        	return y

n = input()
A = map(int, raw_input().split())
p = input()
m = map(int, raw_input().split())

for k in m:
	if solve(k, 0):
		print "Yes"
	else:
		print "No"