-
Notifications
You must be signed in to change notification settings - Fork 83
Open
Description
for : count_of_subsets_with_given_sum.cpp (https://github.com/shubhamchemate003/Dynamic-Programming-Questions-by-Aditya-Verma/blob/main/count_of_subsets_with_given_sum.cpp)
is failing for
n=10
sum=31
arr[] = 9 7 0 3 9 8 6 5 7 6
Working Code :
for(int i=0;i<=sum;i++)
t[0][i]=0;
t[0][0]=1;
for(int i=1;i<=n;i++){
for(int j=0;j<=sum;j++){ // j=0 works for above case though I was not able to find the exact reason for same
if(arr[i-1]<=j)
t[i][j]=t[i-1][j] + t[i-1][j-arr[i-1]];
else
t[i][j]=t[i-1][j]%m;
}
}
Metadata
Metadata
Assignees
Labels
No labels