https://www.acmicpc.net/problem/1937
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
n = int(input())
graph = []
visited = [[0 for _ in range(n)] for _ in range(n)]
dp = [[-1 for _ in range(n)] for _ in range(n)]
for _ in range(n):
temp = list(map(int, input().split(" ")))
graph.append(temp)
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
max_val = 0
cnt = 0
def dfs(x, y):
if dp[x][y] != -1:
return dp[x][y]
dp[x][y] = 1
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if 0<= nx and nx < n and 0<= ny and ny < n and graph[x][y] < graph[nx][ny] and not visited[nx][ny]:
dp[x][y] = max(dp[x][y], dfs(nx, ny)+1)
return dp[x][y]
for i in range(n):
for j in range(n):
max_val = max(max_val, dfs(i,j))
print(max_val)
728x90
반응형
'🔻PS > Baekjoon' 카테고리의 다른 글
[Baekjoon] 백준 21921 블로그 Python (0) | 2024.10.04 |
---|---|
[Baekjoon] 백준 11060 점프 점프 Python (0) | 2024.10.02 |
[Baekjoon] 백준 11048 이동하기 Python (0) | 2024.10.01 |
[Baekjoon] 백준 20056 마법사 상어와 파이어볼 Python (0) | 2024.09.29 |
[Baekjoon] 백준 20922 겹치는 건 싫어 Python (0) | 2024.09.24 |