https://www.codetree.ai/missions/2/problems/tromino/description
n, m = map(int, input().split(" "))
graph = []
visited = [[0 for _ in range(m)] for _ in range(n)]
for _ in range(n):
temp = list(map(int, input().rstrip().split(" ")))
graph.append(temp)
answer = []
max_val = 0
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
def backtrack(dep, x, y):
global max_val
if dep == 3:
temp = answer[::]
max_val = max(max_val, sum(temp))
return
for i in range(4):
nx = x + dx[i]
ny = y + dy[i]
if 0<= nx and nx <n and 0<= ny and ny < m and not visited[nx][ny]:
answer.append(graph[nx][ny])
visited[nx][ny] = 1
backtrack(dep+1, nx, ny)
answer.pop()
visited[nx][ny] = 0
for i in range(n):
for j in range(m):
if not visited[i][j]:
backtrack(0, i, j)
print(max_val)
728x90
반응형
'🔻PS > Codetree' 카테고리의 다른 글
[Codetree] 예술성 Python (1) | 2024.10.15 |
---|---|
[Codetree] 정수 n개의 합 3 Python (0) | 2024.09.19 |
[Codetree] 정수 n개의 합 2 Python (0) | 2024.09.19 |
[Codetree] 수들 중 최솟값 최대화하기 Python (0) | 2024.09.12 |
[Codetree] 외판원 순회 Python (0) | 2024.09.12 |