Recursive dp solution easy to understand c++


#1

Comment body goes here.
int dp[101][101];
int solve(vector<vector > &A,int s,int e,int n,int m)
{
if(s>=n || e>=m || A[s][e]==1)
return 0;
if(s==n-1 && e==m-1)
{
return 1;
}

if(dp[s][e]!=-1)
    return dp[s][e];
int op1=solve(A,s,e+1,n,m);
int op2=solve(A,s+1,e,n,m);
return dp[s][e]=op1+op2;

}
int Solution::uniquePathsWithObstacles(vector<vector > &A) {
int n=A.size();
int m=A[0].size();
memset(dp,-1,sizeof(dp));
return solve(A,0,0,n,m);
}