알고리즘/알고리즘 정리

lru_cache 캐싱을 이용한 dp

에멜라 2023. 2. 19. 17:34

level3 - 숫자 타자 대회

 

기본적인 재귀함수를 쓸 때 불필요한 반복 계산을 줄이기 위해 dp 알고리즘을 사용하는데

 

https://techblog-history-younghunjo1.tistory.com/183

 

[Python] Dynamic Programming(동적계획법) 알고리즘

🔊 이번 포스팅에는 최근에 Python으로 알고리즘을 공부하기 시작하면서 알게 된 여러 알고리즘의 원리와 Python으로 구현하는 방법에 대해 소개해보려 한다. 필자는 최근 알고리즘 공부를 '나동

techblog-history-younghunjo1.tistory.com

 

이때 dp를 사용함에도 불필요하게 시간이 많이 들 수가 있음

이때, 이전 계산에서 동일한 계산이 있었을때, 캐시에 올려져 있는 계산결과를 즉시 가져오는 캐싱을 통해 시간을 더 단축할 수 있다.

 

https://docs.python.org/ko/3/library/functools.html

 

functools — Higher-order functions and operations on callable objects

Source code: Lib/functools.py The functools module is for higher-order functions: functions that act on or return other functions. In general, any callable object can be treated as a function for t...

docs.python.org

https://kimjingo.tistory.com/169

 

[Python] fucntools.lru_cache() - 함수의 결과 캐싱

파이썬의 표준 라이브러리에 있는 functools.lru_cache() 는 함수의 결과를 캐시해 주는 함수 데커레이터입니다. 같은 인수를 전달했던 호출 결과가 이미 캐시되어 있으면 함수를 실행하지 않고 캐시

kimjingo.tistory.com