[백준] 6603번 로또 (파이썬)

서봉성·2023년 5월 20일
0

코딩테스트

목록 보기
14/27

문제

https://www.acmicpc.net/problem/6603

풀이방법

  • 백트래킹을 활용한다.
  • 원소는 오름차순으로 나열되어 있으므로 백트래킹 시 기존에 뽑았던 인덱스보다 이전의 것은 뽑지 않는것이 핵심

코드


def lotto(arr, s, index, cnt):
    if cnt==6:
        print(*arr)
        return
    
    for i in range(index, len(s)):
        arr[cnt]=s[i]
        lotto(arr, s, i+1, cnt+1)
    

while True:
    s = list(map(int, input().split()))
    if s[0]==0:
        break
    arr=[0]*6
    lotto(arr, s[1:], 0, 0)
    print()
profile
OverStudy

0개의 댓글