题解 | #挤奶路径#
挤奶路径
https://www.nowcoder.com/practice/6ab56cedae0646e19fb64b8bdbad82a6
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param cows int整型vector<vector<>> * @return int整型 */ int uniquePathsWithObstacles(vector<vector<int> >& cows) { // write code here int row = cows.size(), col = cows[0].size(); vector<vector<int>> dp(row, vector<int>(col, 0)); for (int i = 0; i < row; i++) { if (cows[i][0] == 1) break; dp[i][0] = 1; } for (int i = 0; i < col; i++) { if (cows[0][i] == 1) break; dp[0][i] = 1; } for (int i = 1; i < row; i++) { for (int j = 1; j < col; j++) { if (cows[i][j] != 1) { dp[i][j] = dp[i-1][j] + dp[i][j-1]; } } } return dp[row-1][col-1]; } };