fork(1) download
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int x;
  5.  
  6. int subset(int a[], int l, int r, int sum=0);
  7.  
  8. int main()
  9. {
  10. ios_base::sync_with_stdio(false);
  11. cin.tie(NULL);
  12. int t;
  13. cin >> t;
  14. while(t--)
  15. {
  16. int n, m;
  17. cin >> n >> m;
  18. ::x = m;
  19. int arr[n];
  20. for(int i=0;i<n;i++)
  21. {
  22. cin >> arr[i];
  23. }
  24. if(subset(arr, 0, n-1))
  25. cout << "Yes" << "\n";
  26. else
  27. cout << "No" << "\n";
  28. }
  29. return 0;
  30. }
  31.  
  32. int subset(int a[], int l, int r, int sum)
  33. {
  34. if(l>r)
  35. {
  36. if(sum==::x)
  37. {
  38. return 1;
  39. }
  40. }
  41. subset(a, l+1, r, sum+a[l]);
  42. subset(a, l+1, r, sum);
  43. return 0;
  44. }
Runtime error #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
Standard output is empty