from sys import stdin
m, n = map(int, stdin.readline().split())
graph = [list(map(int, stdin.readline().split())) for _ in range(m)]
dp = [[-1] * n for _ in range(m)]
dx = [0,0,-1,1]
dy = [-1,1,0,0]
def dfs(x, y):
if x == m - 1 and y == n - 1:
return 1
if dp[x][y] == -1:
dp[x][y] = 0
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if 0 <= nx < m and 0 <= ny < n:
if graph[nx][ny] < graph[x][y]:
dp[x][y] += dfs(nx, ny)
return dp[x][y]
print(dfs(0, 0))
https://simsimjae.tistory.com/20
'문제풀이 > 백준(Boj) 문제풀이' 카테고리의 다른 글
[백준][자료구조/힙] 11279.최대 힙 (파이썬/Python) (0) | 2022.01.08 |
---|---|
[백준][자료구조/힙] 1927.최소 힙 (파이썬/Python) (0) | 2022.01.06 |
[백준][구현] 1009.분산처리 (파이썬/Python) (0) | 2022.01.05 |
[백준][DFS/BFS] 2583. 영역 구하기 (파이썬/Python) (0) | 2021.12.30 |
[백준][Dijkstra/다익스트라] 4885. 녹색 옷 입은 애가 젤다지? (파이썬/Python) (0) | 2021.12.29 |