Skip to content

Commit

Permalink
2025-02-04
Browse files Browse the repository at this point in the history
  • Loading branch information
tgyuuAn committed Feb 3, 2025
1 parent c8cefc2 commit 57dc6e6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tgyuuAn/DFS/๋‚ด๋ฆฌ๋ง‰ ๊ธธ.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import sys
sys.setrecursionlimit(10**6)

def input(): return sys.stdin.readline().rstrip()

M, N = map(int, input().split())
board = [ list(map(int, input().split())) for _ in range(M) ]

dy = [-1, 1, 0, 0]
dx = [0, 0, -1, 1]
dp = [[-1 for _ in range(N)] for _ in range(M)]

def dfs(now):
if now == (N-1, M-1):
return 1

col, row = now
now_value = board[row][col]

if dp[row][col] != -1:
return dp[row][col]

temp = 0
for dir in range(4):
new_col = col + dx[dir]
new_row = row + dy[dir]

if new_col < 0 or new_col > N-1: continue
if new_row < 0 or new_row > M-1: continue
if board[new_row][new_col] >= now_value: continue

temp += dfs((new_col,new_row))

dp[row][col] = temp
return dp[row][col]

print(dfs((0,0)))
1 change: 1 addition & 0 deletions tgyuuAn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,5 @@
| 85์ฐจ์‹œ | 2025.01.09 | ๋‹ค์ต์ŠคํŠธ๋ผ + ์ด๋ถ„ ํƒ์ƒ‰ | <a href="https://www.acmicpc.net/problem/1800">์ธํ„ฐ๋„ท ์„ค์น˜</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/264
| 86์ฐจ์‹œ | 2025.01.16 | ์ด๋ถ„ ํƒ์ƒ‰ | <a href="https://www.acmicpc.net/problem/1114">ํ†ต๋‚˜๋ฌด ์ž๋ฅด๊ธฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/265
| 87์ฐจ์‹œ | 2025.01.31 | ๊ทธ๋ฆฌ๋”” | <a href="https://www.acmicpc.net/problem/8980">ํƒ๋ฐฐ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/268
| 88์ฐจ์‹œ | 2025.02.04 | DFS + DP | <a href="https://www.acmicpc.net/problem/1520">๋‚ด๋ฆฌ๋ง‰ ๊ธธ</a> | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/269
---

0 comments on commit 57dc6e6

Please sign in to comment.