Skip to content

Commit

Permalink
[Bronze I] Title: 일곱 난쟁이, Time: 32 ms, Memory: 31120 KB -BaekjoonHub
Browse files Browse the repository at this point in the history
  • Loading branch information
ddubbu-dev committed Aug 15, 2024
1 parent a75a81e commit 31043d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 33 deletions.
4 changes: 2 additions & 2 deletions 백준/Bronze/2309. 일곱 난쟁이/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

### 성능 요약

메모리: 34272 KB, 시간: 32 ms
메모리: 31120 KB, 시간: 32 ms

### 분류

브루트포스 알고리즘, 정렬

### 제출 일자

2024년 8월 10일 20:24:38
2024년 8월 15일 09:23:21

### 문제 설명

Expand Down
40 changes: 9 additions & 31 deletions 백준/Bronze/2309. 일곱 난쟁이/일곱 난쟁이.py
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

0 comments on commit 31043d5

Please sign in to comment.