Skip to content

Commit 3e2f6b0

Browse files
committed
[BOJ] #1520. 내리막길 / 골드3 / 실패
1 parent d6e6bf0 commit 3e2f6b0

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import sys
2+
3+
sys.setrecursionlimit(10 ** 8)
4+
input = sys.stdin.readline
5+
6+
7+
def dfs(sx, sy):
8+
# 도착 지점에 도달하면 1(한 가지 경우의 수)를 리턴
9+
if sx == m - 1 and sy == n - 1:
10+
return 1
11+
12+
# 이미 방문한 적이 있다면 그 위치에서 출발하는 경우의 수를 리턴
13+
if dp[sx][sy] != -1:
14+
return dp[sx][sy]
15+
16+
ways = 0
17+
for i in range(4):
18+
nx, ny = sx + dx[i], sy + dy[i]
19+
if 0 <= nx < m and 0 <= ny < n and graph[sx][sy] > graph[nx][ny]:
20+
ways += dfs(nx, ny)
21+
22+
dp[sx][sy] = ways
23+
return dp[sx][sy]
24+
25+
26+
m, n = map(int, input().split())
27+
graph = [list(map(int, input().split())) for _ in range(m)]
28+
dp = [[-1] * n for _ in range(m)]
29+
dx, dy = [1, -1, 0, 0], [0, 0, 1, -1]
30+
31+
print(dfs(0, 0))

0 commit comments

Comments
 (0)