Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestCase Failing for above code #4

Open
prompt-07 opened this issue May 21, 2022 · 0 comments
Open

TestCase Failing for above code #4

prompt-07 opened this issue May 21, 2022 · 0 comments

Comments

@prompt-07
Copy link

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;
            }
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant