代码
贪心算法的递归实现 $O(n)$
1 | """递归贪心算法""" |
贪心算法的迭代实现 $O(n)$
1 | def greedy_activity_selector(s,f): |
动态规划的自底向上实现
- (https://wenku.baidu.com/view/bec65461f90f76c661371aa0.html)
参考资料
- 算法导论—贪心算法与动态规划(活动选择问题)
- 活动选择问题(动态规划算法和贪心算法)
- (https://github.com/nbro/ands/blob/702267f868884d4960a5b5b8eddb9a3d94b0a005/ands/algorithms/greedy/activity_selection.py)
- (https://github.com/shaotao1988/Introduction-to-Algrithm/blob/d39ad16f201e55fef10e140d45755af6569940fd/Greedy%20Algrithm/activity_selector.py)
- (https://github.com/buptjz/PythonGod/blob/ecc91524c22dcb7051dc32cccd0cb67af6d1ebaa/IntroToAlgo/Chap16/DynamicActivitySelector.py)
- (https://github.com/yflau/dsapp/blob/013e77352d5efac2f4470ea9c1e94bb939981a40/dsapp/greedy.py)