Please help me in debugging the code . I am total noob

Revision en1, by anshu2002, 2023-03-06 03:57:46

This is was my implementation for previous weekly fourth question what's wrong in my code ?

class Solution {
public:
    vector<vector<int>>dp;
    int solve(int i,vector<vector<int>>&num,int sum){
        if(sum==0)
        {
            return 1;
        }
        if(i==num.size()||sum<0)
            return 0;
        if(dp[i][sum]!=-1)
            return dp[i][sum];
        int ans = 0;
        if(num[i][0]>0)
        {
            num[i][0]--;
            ans+=solve(i,num,sum-num[i][1]);
            ans%=1000000007; 
            num[i][0]++;
        }
        ans+=solve(i+1,num,sum);
        ans%=1000000007;
        return dp[i][sum]=ans;
    }
    int waysToReachTarget(int target, vector<vector<int>>& types) {
        dp = vector<vector<int>>(types.size(),vector<int>(target+1,-1));
        return solve(0,types,target);
    }
};
Tags leetcode, weekly contest

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English anshu2002 2023-03-06 03:57:46 1026 Initial revision (published)