198. House Robber 类别:动态规划 难度:easy
来源:互联网 发布:最容易学的编程语言 编辑:程序博客网 时间:2024/05/20 23:33
题目:
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night.
Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonight without alerting the police.
思路:
转移方程res[i] = max(nums[i - 1] + res[i - 2],res[i - 1])。
程序:
class Solution {public: int rob(vector<int>& nums) { if(nums.size() == 0) return 0; vector<int> res(nums.size() + 1,0); res[1] = nums[0]; for(int i = 2;i <= nums.size();i++) res[i] = max(nums[i - 1] + res[i - 2],res[i - 1]); return res[nums.size()]; }};
0 0
- 198. House Robber 类别:动态规划 难度:easy
- 198.leetcode House Robber(easy)[动态规划]
- 动态规划——198. House Robber[easy]
- 198. House Robber-动态规划
- LeetCode 198. House Robber 213. House Robber II--动态规划
- House Robber 动态规划
- 70. Climbing Stairs 类别:动态规划 难度:easy
- 198. House Robber -Easy
- leetcode 198.House Robber-打家劫舍|动态规划
- 【Leetcode】198. House Robber - - 【动态规划】
- 198. House Robber-leetcode+动态规划
- 动态规划专题之----198. House Robber
- (动态规划)LeetCode#198. House Robber
- leetcode 198. House Robber | 动态规划
- LeetCode 198. House Robber (动态规划)
- Leetcode House Robber 动态规划
- [LeetCode][动态规划]House Robber
- 198. House Robber [easy] (Python)
- Hibernate学习笔记 多表映射
- CF - 55D 数位dp + 状压
- Ubuntu 如何安装 libpcap 库
- 《社会动物——爱、性格和成就的潜在根源》读后感及摘录(4)
- 前端开发人员2017年学习什么
- 198. House Robber 类别:动态规划 难度:easy
- 10 线性表(5)
- js学习笔记:MV*模式
- Python编程:基础学习一
- [Azure]使用Powershell批量添加虚拟机ACL
- Maven的pom.xml介绍
- 矩阵的“特征值分解”和“奇异值分解”区别
- SAUOJ: 说反话(简单字符串处理)
- Python编程:基础学习常见错误整理