PCPP 모의고사 1회 - 체육 대회를 풀어봤다.
이벤에도 처음 시도에서 정답을 맞출 수는 없었지만, 다른 방법을 알아본 후 곧바로 정답을 맞출 수 있었다.
# 1번째 시도 코드
def solution(ability):
answer = 0
childe = {}
length = len(ability[0]) #과목 수를 반환한다.
for n in range(length): #가장 먼저 최고점을 가진 과목의 기준점을 정한다.
max_score = 0
for key, value in enumerate(ability): # 중복되지 않게 학생들의 점수를 dic 변환한다.
childe[key] = value
for v in range(length): # 기준을 포함한 나머지 들을 찾는다.
childe_list= []
for score in childe.values():
childe_list.append(score[v-n])
max_score += max(childe_list) # 해당 기준의 최대값을 찾고 더한다.
childe[childe_list.index(max(childe_list))] = [ -1 for i in childe[childe_list.index(max(childe_list))]] # 해당 기준의 최대값을 가진 학생을 더이상 포함시키지 않기 위해 -1로 전부 변환한다.
answer = max(answer, max_score)
return answer
# 정답 코드
import itertools as it_tools #itertools 모듈을 불러온다.
def solution(ability):
answer = 0
ab_list = it_tools.permutations(ability, len(ability[0]))
# permutations(리스트, 숫자)
# 리스트안에서 숫자 만큼만 나오도록 경우의 수를 만들어 반환한다.
for child_list in list(ab_list): # 반환한 경우의 수를 list로 변경한다.
total = 0
for i in range(len(child_list)):
total += child_list[i][i]
answer = max(answer, total)
return answer