[백준] 18429번 근손실

거북이·2023년 3월 17일
0

백준[실버3]

목록 보기
64/92
post-thumbnail

💡문제접근

  • 중량 키트 순열을 모두 구한 다음에 하루가 지날때마다 하나의 키트를 사용하고 K만큼 중량을 감소시켰을때 500밑으로 내려가는 경우가 존재한다면 멈추고 아니라면 끝까지 돌려서 가능한 경우를 카운팅해주는 방식으로 코드를 작성한다.

💡코드(메모리 : 35692KB, 시간 : 116ms)

from itertools import permutations
import sys
input = sys.stdin.readline

N, K = map(int, input().strip().split())
weight_kit = list(map(int, input().strip().split()))
cnt = 0

for i in list(permutations(weight_kit, len(weight_kit))):
    total_weight = 500
    for j in i:
        total_weight += j
        total_weight -= K
        if total_weight < 500:
            break
    else:
        if total_weight >= 500:
            cnt += 1
print(cnt)

💡소요시간 : 14m

0개의 댓글