fork download
  1. from fractions import gcd
  2. import math
  3. from itertools import permutations
  4. from itertools import combinations
  5. import calendar
  6. from itertools import product
  7. def readInts():
  8. return list(map(int, raw_input().strip().split()))
  9. def readInt():
  10. return int(raw_input())
  11. def isSubsetSum(st, n, sm) :
  12. # arr, n, k
  13. subset=[[True] * (sm+1)] * (n+1)
  14. for i in range(0, n+1) :
  15. subset[i][0] = True
  16. for i in range(1, sm + 1) :
  17. subset[0][i] = False
  18. for i in range(1, n+1) :
  19. for j in range(1, sm+1) :
  20. if(j < st[i-1]) :
  21. subset[i][j] = subset[i-1][j]
  22. if (j >= st[i-1]) :
  23. subset[i][j] = subset[i-1][j] or subset[i - 1][j-st[i-1]]
  24. return subset[n][sm];
  25.  
  26. mod = 10 ** 9 + 7
  27. # for i,j in product(xrange(R),xrange(C)):
  28.  
  29. for __ in range(readInt()):
  30. n,k = readInts()
  31. arr =readInts()
  32. if (isSubsetSum(arr, n, k) == True) :
  33. print "YES!"
  34. else:
  35. print "NO!"
  36.  
  37.  
  38. '''
  39. Input:
  40. 2
  41. 3 10
  42. 8 3 2
  43. 2 20
  44. 11 11
  45.  
  46. Output:
  47. YES!
  48. NO!
  49. '''
  50.  
Success #stdin #stdout 0.03s 8576KB
stdin
2
3 10
8 3 2
2 20
11 11
stdout
YES!
NO!