728x90
3980번: 선발 명단
각각의 테스트 케이스에 대해서, 모든 포지션의 선수를 채웠을 때, 능력치의 합의 최댓값을 출력한다. 항상 하나 이상의 올바른 라인업을 만들 수 있다.
www.acmicpc.net
for tc in range(int(input())):
player = [0] * 11
for i in range(11):
player[i] = list(map(int,input().split()))
visit = [0] * 11
max_val = 0
def comb(index=0, total=0):
if index == 11:
global max_val
if max_val < total:
max_val = total
else:
for i in range(11):
if not player[i][index] or visit[i] == 1: continue
visit[i] = 1
comb(index+1, total+player[i][index])
visit[i] = 0
comb()
print(max_val)
모든 조합을 구하는 문제인데, 조건을 주어서 빠져나오는 백트래킹을 사용하면 된다.
모든 조합을 만들면서 조건을 주어서 빠져나오는 것만 하면 백트래킹인지는 모르겠다.
'STUDY > Algorithm' 카테고리의 다른 글
[백준] 2468 안전영역 (0) | 2021.03.06 |
---|---|
[백준] 1759 암호만들기 (0) | 2021.03.05 |
[백준] 6603 로또 (0) | 2021.03.04 |
[백준] 2583 영역구하기 (0) | 2021.03.04 |
[백준] N과 M (시리즈) (0) | 2021.03.04 |