Guest User

Untitled

a guest
Jan 2nd, 2020
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3. int size;
  4. int count = 0;
  5. bool subsetSum(int *a, int n, int sum ){
  6.     if(count == 1)
  7.         return true ;
  8.     if(sum == 0 && n != size - 1){
  9.         cout<<"Yes"<<endl;
  10.         count = 1;
  11.         return true;
  12.     }
  13.     if(n == 0)
  14.         return false;
  15.     //not including last element    
  16.     subsetSum(a, n - 1, sum);
  17.     //including last element
  18.     subsetSum(a, n - 1, sum - a[n-1] );
  19.     return false;
  20.    
  21. }
  22.  
  23. int main(){
  24.     int t;
  25.     cin>>t;
  26.     while(t--){
  27.       //  int n;
  28.         cin>>size;
  29.         int a[size];
  30.         count = 0;
  31.         for(int j = 0; j < size; j++){
  32.             cin>>a[j];
  33.         }
  34.        
  35.         if(!subsetSum(a, size - 1, 0))
  36.             cout<<"No"<<endl;
  37.     }
  38.     return 0;
  39. }
Add Comment
Please, Sign In to add comment