<h3><a title="题目描述" href="https://leetcode-cn.com/problems/house-robber/">题目描述</a></h3>
![file](https://i.loli.net/2019/11/06/icS4ms5aun6fJPT.png)
<h4>解法:</h4>
<pre class="EnlighterJSRAW" data-enlighter-language="null">class Solution:
def rob(self, nums: List[int]) -> int:
cur, pre = 0,0
for num in nums:
cur,pre = max(cur,pre + num),cur
return cur</pre>
#### Note
- 动态规划好像比之前会写一些了 但还是菜。
- [简单易懂的题解分析](https://leetcode-cn.com/problems/house-robber/solution/da-jia-jie-she-dong-tai-gui-hua-jie-gou-hua-si-lu-/ "简单易懂的题解分析")
- **重点在思考状态以及转移方程如何定义**
- 又懒又菜。
- 有一个很有意思的点不得不提 ~~当然也有我太菜的问题~~
<pre class="EnlighterJSRAW" data-enlighter-language="null">
cur = max(cur,pre + num)
pre = cur
</pre>
其实我原先的思路转换成代码时是这么写的,果然错了-。-
<pre class="EnlighterJSRAW" data-enlighter-language="null">
cur = 5
pre = 0
num = 6
cur,pre = max(cur, pre+num) ,cur //输出cur = 6,pre = 5
//错误的情况:
cur = max(cur,pre+num) //cur = 6
pre = cur //pre=6
</pre>
也就是说要做到同时赋值还是用a,b = c,d 比较合理
Leetcode198 打家劫舍