i have written another code for subset sum problem.tell me what is the problem with it.why its not working?also explain the time complexity of the code given in the webinar for subsums problem
#include
using namespace std;
int subsetsum(int arr[],int n,int a,int b)
{
//base case
if(n==0)
{
if(0>=a and 0<=b)
return 1;
else
return 0;}
int no1=subsetsum(arr,n-1,a,b);
int no2=subsetsum(arr,n-1,a-arr[n-1],b-arr[n-1]);
int no3;
if(arr[n-1]<0)
no3=subsetsum(arr,n-1,a-arr[n-1],b);
else
no3=subsetsum(arr,n-1,a,b-arr[n-1]);
int no=no1+no2-no3;
return no;
}
int main()
{
int arr[100];
int n,a,b;
cin>>a>>b;
for(int i=0;i<n;i++)
cin>>arr[i];
int no=subsetsum(arr,n,a,b);
cout<<" number of subsets having sum between "<<a<< " and "<<b<<" both inclusive is: "<<no<<endl;
return 0;
}