Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int size;
- int count = 0;
- bool subsetSum(int *a, int n, int sum ){
- if(count == 1)
- return true ;
- if(sum == 0 && n != size - 1){
- cout<<"Yes"<<endl;
- count = 1;
- return true;
- }
- if(n == 0)
- return false;
- //not including last element
- subsetSum(a, n - 1, sum);
- //including last element
- subsetSum(a, n - 1, sum - a[n-1] );
- return false;
- }
- int main(){
- int t;
- cin>>t;
- while(t--){
- // int n;
- cin>>size;
- int a[size];
- count = 0;
- for(int j = 0; j < size; j++){
- cin>>a[j];
- }
- if(!subsetSum(a, size - 1, 0))
- cout<<"No"<<endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment