알고리즘 문제 풀기/백준(Baekjoon)
[백준 알고리즘] 6603.로또 - 조합
hibscus
2021. 3. 21. 23:52
6개의 로또 숫자를 뽑는 것이므로 조합이고, 중복되는 값이 있으면 안된다.
그래서 start로 범위를 이전보다 다음에서 시작하게 만들어 풀었다.
def lotto(idx, start):
if idx == 6:
print(" ".join(select))
return
for i in range(start, k):
select[idx] = S[i]
lotto(idx+1, i+1)
select = [0] * 6
while True:
nums = list(input().split())
k, S = int(nums[0]), nums[1:]
if k == 0:
break
lotto(0, 0)
print()
풀다보니 이제는 자동적으로 if idx == M : 이런식으로 코드를 작성하게 된다..
조합과 순열은 결국 많이 풀어봐야 익숙해지는 것 같다ㅎㅎ