[Programmers] νΌλ‘λ
Updated:
νΌλ‘λ
νΌλ‘λλ₯Ό ν΄λ¦νλ©΄ λ°λ‘ μ΄λνλ€.
λμ μ μ΅λ κ°μκ° 8κ°μ΄κΈ° λλ¬Έμ μμ΄μ ν΅ν΄ μμ νμνλ©΄ λ΅μ ꡬν μ μλ€.
λ€λ₯Έ λ°©λ²μΌλ‘λ λ΅μ ꡬν μ μμκΉ νμ°Έ μκ°ν΄λ΄€λλ° μ λ§ μλ€!
κ·ΈλΌ λμ κ°μκ° 1000κ°λ§ μ£Όμ΄μ Έλ 1000! κ°μμ μμ΄μ νμν΄μΌνλλ°..
λ ν¨μ¨μ μΈ λ°©λ²μ μλ건κ°?
from itertools import permutations
def solution(k, dungeons):
answer = float('-inf')
# 1. λ°©λ¬Έ ν λμ μμ΄ κ΅¬νκΈ°
for permutations_dungeons in permutations(dungeons):
cur_tired = k
tmp_answer = 0
for dungeon in permutations_dungeons:
min_tired = dungeon[0]
use_tired = dungeon[1]
# 2. νμ¬ νΌλ‘λκ° μ΅μ μꡬ νΌλ‘λ μ΄μμ΄λΌλ©΄ λμ νν
if min_tired <= cur_tired:
cur_tired -= use_tired
tmp_answer += 1
answer = max(tmp_answer, answer)
return answer
if __name__ == "__main__":
k = 80
dungeons = [[80, 20], [50, 40], [30, 10]]
print(solution(k, dungeons))
Leave a comment