https://www.acmicpc.net/problem/6603
6603번: 로또
입력은 여러 개의 테스트 케이스로 이루어져 있다. 각 테스트 케이스는 한 줄로 이루어져 있다. 첫 번째 수는 k (6 < k < 13)이고, 다음 k개 수는 집합 S에 포함되는 수이다. S의 원소는 오름차순으로
www.acmicpc.net
그냥 구현하는문제인듯
처음에한 뻘짓
로또번호를 먼져 구하고, 그 다음에 모든경우의수 구하기
머리가 나쁘면 손이고생함
lotto_numbers=[]
def make_lotto_numbers(start=0):
if len(lotto_numbers)==k:
make_lotto(lotto_numbers)
return
for i in range(start,k):
if t_case[i] not in lotto_numbers:
lotto_numbers.append(t_case[i])
make_lotto_numbers(start+1)
lotto_numbers.pop()
return
lotto=[]
def make_lotto(lotto_numbers,start=0):
if len (lotto)==6:
print(* lotto)
return
for i in range(start,k):
if lotto_numbers[i] not in lotto:
lotto.append(lotto_numbers[i])
make_lotto(lotto_numbers,i+1)
lotto.pop()
return
while True:
tmp=[*map(int,input().split())]
if tmp[0]==0:exit()
k,t_case=tmp[0],tmp[1:]
make_lotto_numbers()
print()
간단한 풀이
그냥 처음부터 6자리 모든 경우의 수를 구하면 됨
모듈을 쓴다면 더 간편
lotto=[]
def dfs(start=0):
if len (lotto)==6:
print(* lotto)
return
for i in range(start,len(s)):
if s[i] not in lotto:
lotto.append(s[i])
dfs(i+1)
lotto.pop()
while True:
s=[*map(int,input().split())]
if s[0]==0:exit()
s=s[1:]
dfs()
print()
이터툴즈이용하기
from itertools import combinations
while True:
s=[*map(int,input().split())]
if s[0]==0:exit()
s=s[1:]
s=list(combinations(s,6))
for tmp in s:
print(* tmp)
print()
진짜 머리가모자라면 손이고생함
'boj' 카테고리의 다른 글
| 백준 14051 퇴사 (0) | 2022.04.12 |
|---|---|
| 백준 1759 암호 만들기 (0) | 2022.04.11 |
| 백준 10971 외판원 순회 2 (0) | 2022.04.11 |
| 백준 7576 토마토 (0) | 2022.04.09 |
| 백준 1003 피보나치 함수 (0) | 2022.04.08 |