Skip to content

Commit 24e1242

Browse files
committed
[BOJ]#6603. 로또/실버2/45min
https://www.acmicpc.net/problem/6603
1 parent 6db6e68 commit 24e1242

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Hongjoo/백준/로또.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
[BOJ]6603로또/실버2
3+
https://www.acmicpc.net/problem/6603
4+
5+
-주어진 K개(k>6) 숫자에 6개 뽑아 대해 중복x 한 조합의 경우의 수 찾기
6+
->중복 x , 순서 상관x
7+
- 해당 모든 경우의 수는 사전 순으로 출력
8+
- 입력 : K , {해당하는 숫자의 조합}
9+
"""
10+
11+
import sys
12+
input = sys.stdin.readline
13+
# 1. 입력 변수 및 출력 형식에 맞춰 설정하기
14+
while True :
15+
set_s = list(map(int, input().split()))
16+
answer = []
17+
if len(set_s) < 2 :
18+
break
19+
k= set_s.pop(0)
20+
#2. 유효성 검사 is_valid 정의
21+
# check = [True]*len(set_s[1:])
22+
result = [0]*6 # 출력 리스트
23+
#3. 백트래킹 함수 정의
24+
def conbination(level ,idx ):
25+
#종료 조건
26+
if level == 6 :
27+
answer.append(result.copy())
28+
# print(result)
29+
return
30+
# 동작 과정
31+
for i in range(idx,k):
32+
result[level] = set_s[i]
33+
conbination(level+1 ,i+1) # 조합은 idx 보다 작은 i는 탐색 할 필요 없음
34+
result[level] = 0
35+
conbination(0,0)
36+
# print(answer)
37+
# 3. 출력 형식 맞추기
38+
for a in answer:
39+
print(" ".join(map(str,a)))
40+
print("")

0 commit comments

Comments
 (0)