문제는 보고오셨겠죠?!

아이디어 1 : dfs / bfs

아이디어 2 : 중복조합

저는 파이써닉하니까

itertools의 combinations_with_replacement 메소드를 사용하겠습니다.

case1: 라이언이 지는 경우 -1 반환

case2: 둘 다 0점인 과녁의 경우는 continue

1. answer=[-1] , case1의 경우 초기 선언 값이 반환

2. combinations이 만들어준 조합을 info2에 넣어주고 비교하여 max값을 비교연산하는 시퀀스!!

from itertools import combinations_with_replacement
def solution(n,info):
    answer=[-1] 
    gap=-1
    for combi in combinations_with_replacement(range(11),n):
        info2 = [0]*11
        for i in combi:
            info2[10-i]+=1
        lion,peach=0,0
        for i in range(11):
            if info[i]==0 and info2[i]==0:
                continue
            elif info[i]>= info2[i]:
                peach+=10-i
            else:
                lion+=10-i

        if lion>peach:
            temp_gap = lion-peach
            if temp_gap> gap:
                gap=temp_gap
                answer= info2
    return answer
profile
충분한 전기와 컴퓨터 한 대와 내 이 몸만 남아 있다면 지구를 재건할 수 있습니다.

0개의 댓글

Powered by GraphCDN, the GraphQL CDN