Leetcode 63. 다른 경로 II

2174 단어
동적 기획
class Solution {
public:
    int dp[105][105]={};
    bool _place(int i,int j,int n,int m){
        return i>=0 && i=0 && jint uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) {
        int n=obstacleGrid.size(),m=n==0?0:obstacleGrid[0].size();
        dp[0][0]=1;
        for(int i=0;ifor(int j=0;jif(obstacleGrid[n-1-i][m-1-j]) dp[i][j]=0;
                else{
                    if(_place(i-1,j,n,m)) dp[i][j]+=dp[i-1][j];
                    if(_place(i,j-1,n,m)) dp[i][j]+=dp[i][j-1];
                }
         return dp[n-1][m-1];
    }
};

좋은 웹페이지 즐겨찾기