본문 바로가기
백준알고리즘/브루트 포스

(Python/🥉1)백준 알고리즘 2309번: 일곱 난쟁이

by windy7271 2023. 3. 22.
728x90
반응형

문제 출처: https://www.acmicpc.net/problem/2309

 

2309번: 일곱 난쟁이

아홉 개의 줄에 걸쳐 난쟁이들의 키가 주어진다. 주어지는 키는 100을 넘지 않는 자연수이며, 아홉 난쟁이의 키는 모두 다르며, 가능한 정답이 여러 가지인 경우에는 아무거나 출력한다.

www.acmicpc.net

풀이:

import sys
from itertools import combinations

sys.stdin = open('/Users/song/Desktop/Python/Python/h.txt', 'r')

lst = []
for i in range(9):
    lst.append(int(input()))
res = []
for i in list(combinations(lst, 7)):
    if sum(i) == 100:
        print(*sorted(i), sep="\n")
        break

 

반응형

댓글