grid dp elephant ways
I want sol for elephat question
Just keep this logic in mind that
dp[x][y] = Σdp[k][y] (where k ranges from 0 to x-1)+ Σdp[x][l] (where l ranges from 0 to y-1), and k in the question is not a value. It can be any number ranging less then value of i or j for current dp i,j cell. Also this code is for no obstacle. For obstacle just add an if condition.
int ElephantGrid(int m, int n){
int dp[m][n]={0};
dp[0][0]=1;
for(int i=0;i<n-1;i++){
for(int j=0;j<m-1;j++){
int x1=0,x2=0;
for(int k=0;k<i-1;k++){
x1+=dp[k][j];
}
for(int k=0;k<j-1;k++){
x2+=dp[i][k]
}
dp[i][j]=x1+x2;
}
}
return dp[m-1][n-1];
}