Skip to content

TestCase Failing for above code #4

@prompt-07

Description

@prompt-07

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions