-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Bronze I] Title: 일곱 난쟁이, Time: 32 ms, Memory: 31120 KB -BaekjoonHub
- Loading branch information
1 parent
a75a81e
commit 31043d5
Showing
2 changed files
with
11 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,17 @@ | ||
""" | ||
[문제 이해] | ||
- 9명 중 7명 키 합을 구해서 = 100인 경우 | ||
- 난쟁이들 키 오름차순 출력 | ||
[풀이] | ||
- 조합으로 9C7 경우의 수 찾기 | ||
""" | ||
from itertools import combinations | ||
|
||
N = 9 | ||
arr = [] | ||
for i in range(N): | ||
arr.append(int(input())) | ||
|
||
# 탐색 - | ||
def make조합_중복없음(arr: list, cnt: int): | ||
result = [] | ||
|
||
def inner(arr, start_idx, picked_arr): | ||
if len(picked_arr) == cnt: | ||
result.append(picked_arr) | ||
return | ||
for i in range(start_idx, len(arr)): | ||
inner(arr, i + 1, picked_arr[:] + [arr[i]]) | ||
|
||
inner(arr, 0, []) | ||
|
||
return result | ||
nums = [int(input()) for _ in range(N)] | ||
|
||
|
||
cases = combinations(nums, 7) | ||
|
||
collections = make조합_중복없음(arr, 7) | ||
|
||
for case in collections: | ||
acc = sum(case) | ||
for case in cases: | ||
sorted_case = sorted(list(case)) | ||
acc = sum(sorted_case) | ||
|
||
if acc == 100: | ||
print("\n".join(map(str, sorted(case)))) | ||
break | ||
for item in sorted_case: | ||
print(item) | ||
break |