What is missing in my code? Why is it missing some testcases in the judge

Правка en1, от Medeali, 2023-08-10 17:55:54

my code :

include

using namespace std; int subsum(int A[],int n,int index,int sum,int x){ if(sum==x && index!=0) return 1; if(index==n) return 0; return subsum(A,n,index+1,sum+A[index],x)+subsum(A,n,index+1,sum,x);

} int main() { int n,x; cin>>n>>x; int A[n]; for(int i=0;i<n;i++) cin>>A[i]; int b=subsum(A,n,0,0,x); if(x==0) b++; cout<<b; return 0; } Given an array A of N elements and an integer K , we want you to calculate the number of subsets of A whose sum of elements is equal to K .

B is a subset of A if B can be obtained by removing zero or more elements from A .

Теги brute force

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский Medeali 2023-08-10 17:55:54 782 Initial revision (published)