使用DFS,不知道会不会超时 res = 0 def search(row, rows, col, cols, borad): global res if row == rows-1 and col == cols-1: res+=1 return if row < 0&nbs***bsp;row >=rows&nbs***bsp;col < 0&nbs***bsp;col >= cols: return if borad[row][col] == 1: return search(row, rows, col+1, cols, borad) search(row+1, rows, col+1, cols, borad) search(row-1, rows, col+1, cols, borad) a =[ [0,0,1,0,1], [1,1,0,0,0] ] search(0,2,0,5,a) print(res)