[Softeer - level3] 택배 λ§ˆμŠ€ν„° κ΄‘μš°

2023. 7. 24. 16:08Β·Algorithm/Softeer

 

import sys
input = sys.stdin.readline 

from itertools import permutations

# 레일의 μˆœμ„œλ₯Ό μ‘°μž‘ν•΄μ„œ μ΅œμ†Œν•œμ˜ 무게만 λ“€ 수 있게 ν•˜μž 
n,m,k = map(int,input().split())
# n : 레일 / m : 택배 무게 / k : μ‹œν–‰ 횟수
result = 100000 # μ΅œμ†Œλ¬΄κ²Œ 

rail = list(map(int,input().split()))
rail_list = list(permutations(rail)) # μˆœμ—΄ 

def cal(current):
    total_weight, weight = 0, current[0]
    idx, cnt = 0, 0

    while cnt < k:
        next_weight = current[(idx+1)%n]
        if weight + next_weight > m:
            total_weight += weight
            weight = next_weight
            cnt += 1
        else:
            weight += next_weight
        idx += 1
    
    return total_weight

for x in rail_list:
    result = min(result,cal(x))

print(result)

 

 

 

μˆœμ—΄(Permutation)

permutations(λ°°μ—΄, λ½‘λŠ” 개수)

from itertools import permutations
 
a = [1,2,3,4]
res = permutations(a, 2)
print(list(res)) # list와 같이 써야 κ²°κ³Όλ₯Ό λ³Ό 수 μžˆλ‹€.

 

 

 

μ €μž‘μžν‘œμ‹œ

'Algorithm > Softeer' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€

[Softeer - level2] 8단 변속기  (0) 2023.07.25
[Softeer - level3] 슀마트 λ¬Όλ₯˜  (0) 2023.07.24
[Softeer - level2] [21λ…„ 재직자 λŒ€νšŒ μ˜ˆμ„ ] λΉ„λ°€ 메뉴  (0) 2023.07.23
[Softeer - level2] GBC  (0) 2023.07.23
[Softeer - level2] [21λ…„ 재직자 λŒ€νšŒ μ˜ˆμ„ ] μ „κ΄‘νŒ  (0) 2023.07.23
'Algorithm/Softeer' μΉ΄ν…Œκ³ λ¦¬μ˜ λ‹€λ₯Έ κΈ€
  • [Softeer - level2] 8단 변속기
  • [Softeer - level3] 슀마트 λ¬Όλ₯˜
  • [Softeer - level2] [21λ…„ 재직자 λŒ€νšŒ μ˜ˆμ„ ] λΉ„λ°€ 메뉴
  • [Softeer - level2] GBC
hello_u
hello_u
  • hello_u
    😜
    hello_u
  • 전체
    였늘
    μ–΄μ œ
    • 😜 (345)
      • Hardware (2)
        • BMC (2)
      • Spring (109)
        • Spring μž…λ¬Έ (20)
        • Spring κΈ°λ³Έ (27)
        • Spring MVC (18)
        • Spring DB (22)
        • Spring JPA κΈ°λ³Έ (16)
        • Spring JPA ν™œμš© (6)
      • Develop (27)
        • DB (8)
        • JAVA (4)
        • Web (2)
        • Python (7)
        • OSS (2)
        • Git (2)
        • API (2)
      • Algorithm (155)
        • CodeUp 기초 (44)
        • 파이썬 μ½”λ”©ν…ŒμŠ€νŠΈ (64)
        • ν”„λ‘œκ·Έλž˜λ¨ΈμŠ€ (4)
        • SWEA (30)
        • Softeer (10)
        • BOJ (2)
      • CS (9)
        • μ»΄ν“¨ν„°μΌλ°˜ (3)
        • 운영체제 (3)
        • λ°μ΄ν„°λ² μ΄μŠ€ (0)
        • 정보톡신 (1)
        • 자료ꡬ쑰 (1)
        • μ†Œν”„νŠΈμ›¨μ–΄ 곡학 (1)
        • ν”„λ‘œκ·Έλž˜λ° μ–Έμ–΄ (0)
        • μ΅œμ‹  λ””μ§€ν„Έ, μΌλ°˜μƒμ‹ (0)
      • 자격증 (41)
        • μ •λ³΄λ³΄μ•ˆκΈ°μ‚¬ (9)
        • μ •λ³΄μ²˜λ¦¬κΈ°μ‚¬ (22)
        • λ¦¬λˆ…μŠ€λ§ˆμŠ€ν„° 1κΈ‰ (3)
        • SQLD (7)
  • hELLOΒ· Designed Byμ •μƒμš°.v4.10.3
hello_u
[Softeer - level3] 택배 λ§ˆμŠ€ν„° κ΄‘μš°
μƒλ‹¨μœΌλ‘œ

ν‹°μŠ€ν† λ¦¬νˆ΄λ°”