Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int countpath(int m,int n,int i,int j, vector<vector<int>> &dp)
- {
- if(i==m-1 && j==n-1)
- {
- return 1;
- }
- if(i==m || j==n)
- {
- return 0;
- }
- if(dp[i][j]!=0)
- {
- return dp[i][j];
- }
- return dp[i][j] = countpath(m,n,i+1,j,dp)+countpath(m,n,i,j+1,dp);
- }
- int uniquePaths(int m, int n) {
- vector<vector<int> > dp(m+1, vector<int>(n+1, 0));
- return countpath(m,n,0,0,dp);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment