We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f0078f4 commit 70b2be2Copy full SHA for 70b2be2
YoonYn9915/dp/2025-02-22-[백준]-#1520-내리막길.py
@@ -0,0 +1,41 @@
1
+import sys
2
+
3
+input = sys.stdin.readline
4
+sys.setrecursionlimit(10 ** 8)
5
+n, m = map(int, input().split())
6
+graph = []
7
8
+moves = [
9
+ [1, 0],
10
+ [0, 1],
11
+ [-1, 0],
12
+ [0, -1]
13
+]
14
15
+visited = [[-1] * m for _ in range(n)]
16
+for _ in range(n):
17
+ graph.append(list(map(int, input().split())))
18
19
20
+def dfs(x, y):
21
+ # Base Case
22
+ if x == n - 1 and y == m - 1:
23
+ return 1
24
25
+ # 이미 방문한 곳일 때
26
+ if visited[x][y] != -1:
27
+ return visited[x][y]
28
29
+ visited[x][y] = 0
30
31
+ for move in moves:
32
+ nx, ny = x + move[0], y + move[1]
33
34
+ if 0 <= nx < n and 0 <= ny < m:
35
+ if graph[x][y] > graph[nx][ny]:
36
+ visited[x][y] += dfs(nx, ny)
37
38
39
40
41
+print(dfs(0, 0))
0 commit comments