File tree Expand file tree Collapse file tree
_WeeklyChallenges/W19-[Graph-Backtracking] Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44유형: Graph, Backtracking
55"""
66
7- # 토요일에 업로드 예정
7+ """
8+ #6603. 로또
9+ 백트래킹 풀이
10+ """
11+ import sys
12+ input = sys .stdin .readline
13+ def backtrack (lotto , current ):
14+ if len (lotto ) == 6 : # 종료조건
15+ print (' ' .join (map (str , lotto )))
16+ return
17+
18+ for i in range (current , k ):
19+ lotto .append (S [i ])
20+ backtrack (lotto , i + 1 )
21+ lotto .pop ()
22+
23+
24+ while True :
25+ testcase = input ().strip ()
26+ if testcase == '0' :
27+ break
28+ nums = list (map (int , testcase .split ()))
29+ k , S = nums [0 ], nums [1 :]
30+
31+ backtrack ([], 0 )
32+ print ()
33+
34+
35+ """
36+ #6603. 로또
37+ 조합 풀이
38+ """
39+ import sys
40+ from itertools import combinations
41+ input = sys .stdin .readline
42+
43+ while True :
44+ testcase = input ().strip ()
45+ if testcase == '0' :
46+ break
47+ nums = list (map (int , testcase .split ()))
48+ k , S = nums [0 ], nums [1 :]
49+ combs = list (combinations (S , 6 ))
50+ for comb in combs :
51+ print (' ' .join (map (str , comb )))
52+ print ()
You can’t perform that action at this time.
0 commit comments