💡문제접근
- 간단한 문제였는데 조금 시간이 오래 걸렸던 백트래킹 문제였다. 선수의 포지션별 스탯의 총합이 최대가 되도록 넣고 빼는 작업을 반복하는 백트래킹 함수를 작성해서 문제를 해결했다.
💡코드(메모리 : 31256KB, 시간 : 88ms)
import sys
input = sys.stdin.readline
def recursive(idx, score):
global Max_score
if idx == 11:
if score > Max_score:
Max_score = score
return Max_score
for i in range(11):
if visited[i] or not stats[i]:
continue
if stats[idx][i] > 0:
visited[i] = True
recursive(idx + 1, score + stats[idx][i])
visited[i] = False
T = int(input())
for _ in range(T):
stats = []
Max_score = 0
visited = [False] * 11
player = [0] * 11
for i in range(11):
stats.append(list(map(int, input().split())))
recursive(0, 0)
print(Max_score)
💡소요시간 : 47m