Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
1,027 views
in Online Assessments by Expert (46,090 points) | 1,027 views

2 Answers

0 like 0 dislike
#include<iostream>

#include<bits/stdc++.h>

using namespace std;

#define mod 1000000007;

int solve(int m,int n,int i,int j,int maxmove,vector<vector<int>>grid)

{  

    if(maxmove<0 )

    {

        return 0;

    }

    if(i<0 ||j<0 || i>=m ||j>=n)

    {

        return 1;

    }

 

    int up=solve(m,n,i-1,j,maxmove-1,grid)%mod;

    int down=solve(m,n,i+1,j,maxmove-1,grid)%mod;

    int left=solve(m,n,i,j-1,maxmove-1,grid)%mod;

    int right=solve(m,n,i,j+1,maxmove-1,grid)%mod;

 

    return (up+down+left+right)%mod;

}

int main()

{

    int m=2,n=2;

    int maxmove=2;

    int startRow=0,startCol=0;  

    vector<vector<int>>grid(m,vector<int>(n,1));

    //find ways to get out of this grid

   cout<< solve(m,n,startRow,startCol,maxmove,grid);  

}
by Expert (660 points)
0 like 0 dislike

Images of ques

imageimageimageimage

 

by Expert (46,090 points)