https://www.codetree.ai/missions/2/problems/maximin-of-numbers/description
n = int(input())
graph = []
for _ in range(n):
temp = list(map(int, input().rstrip().split(" ")))
graph.append(temp)
num = [i for i in range(n)]
visited = [0 for _ in range(n)]
result = []
answer = []
min_vals = []
def find_min_val(answer):
cnt = 10000
for i, j in zip(num, answer):
cnt = min(cnt, graph[i][j])
min_vals.append(cnt)
def backtrack(dep):
if dep == n:
temp = answer[::]
result.append(temp)
find_min_val(temp)
return
for i in range(n):
if not visited[i]:
answer.append(num[i])
visited[i] = 1
backtrack(dep+1)
answer.pop()
visited[i] = 0
backtrack(0)
print(max(min_vals))
728x90
반응형
'🔻PS > Codetree' 카테고리의 다른 글
[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 |
[Codetree] 1차원 윷놀이 Python (3) | 2024.09.08 |