[백준/Python] DFS/BFS - 6603번 로또

Sujin Lee·2022년 4월 15일
0

코딩테스트

목록 보기
23/172
post-thumbnail

👩🏻‍🏫 풀이

import sys

# 재귀함수를 이용한 조합 구현
def combination(arr, n):
  result = []
  if n == 0:
    return [[]]
  for i in range(len(arr)):
    elem = arr[i]
    for rest in combination(arr[i+1:],n-1):
      result.append([elem]+rest)
  return result

nums = [] 
while True:
  lst = list(map(int,sys.stdin.readline().split()))
  if lst[0] == 0:
    break
  del lst[0]
  for i in combination(lst,6): 
    for j in i:
      print(j, end=" ")
    print()
  print()
  • 헷갈린 부분: 입력을 다 받고, 테스트 케이스 순서대로 출력되어야하는 줄 알았는데 그게 아니었음.
# 출력
7 1 2 3 4 5 6 7
1 2 3 4 5 6 
1 2 3 4 5 7 
1 2 3 4 6 7 
1 2 3 5 6 7 
1 2 4 5 6 7 
1 3 4 5 6 7 
2 3 4 5 6 7 

8 1 2 3 5 8 13 21 34
1 2 3 5 8 13 
1 2 3 5 8 21 
1 2 3 5 8 34 
1 2 3 5 13 21 
1 2 3 5 13 34 
1 2 3 5 21 34 
1 2 3 8 13 21 
1 2 3 8 13 34 
1 2 3 8 21 34 
1 2 3 13 21 34 
1 2 5 8 13 21 
1 2 5 8 13 34 
1 2 5 8 21 34 
1 2 5 13 21 34 
1 2 8 13 21 34 
1 3 5 8 13 21 
1 3 5 8 13 34 
1 3 5 8 21 34 
1 3 5 13 21 34 
1 3 8 13 21 34 
1 5 8 13 21 34 
2 3 5 8 13 21 
2 3 5 8 13 34 
2 3 5 8 21 34 
2 3 5 13 21 34 
2 3 8 13 21 34 
2 5 8 13 21 34 
3 5 8 13 21 34 

0
profile
공부한 내용을 기록하는 공간입니다. 📝

0개의 댓글