Skip to content

Commit 70b2be2

Browse files
committed
[BOJ] 내리막길 / 골드 3 / 80분 실패
https://www.acmicpc.net/problem/1520
1 parent f0078f4 commit 70b2be2

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
return visited[x][y]
39+
40+
41+
print(dfs(0, 0))

0 commit comments

Comments
 (0)