摘要: ## 1. 路径选择 #### 1.1. House Robber ```txt 给一个自然数数组,在不允许相邻取的情况下,求可取的最大和 Input: [1,2,3,1] Output: 4 取1,3和为4 方法:设定状态dp[n]表示前n项在不能相邻取情况下最大和取法的最大和(结果),要用前面信 阅读全文
posted @ 2023-08-03 19:39 xytpai 阅读(12) 评论(0) 推荐(0) 编辑
摘要: #### 1. 斐波那契数列的第n项 ```python def Fibonacci(self, n): if n==0: return 0 if n==1: return 1 a, b, c = 0, 1, -1 for i in range(2, n + 1): c = a + b a = b 阅读全文
posted @ 2023-08-03 19:17 xytpai 阅读(13) 评论(0) 推荐(0) 编辑