House Robber 动态规划
来源:互联网 发布:股票交易软件 编辑:程序博客网 时间:2024/04/29 20:17
House Robber
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 tonightwithout alerting the police.
class Solution {public://在某个数组里面找一个序列, 序列里面的每一个元素都不能相邻,然后求其最大和//当前可以选择偷和不偷,dp[i]=max(dp[i-1],num[i]+dp[i-2])不偷就是dp[i-1],偷就是dp[i-2]+num[i] int rob(vector<int>& nums) { int len=nums.size(); if(len==0) return 0; else if(len==1) return nums[0]; int *dp=new int[len]; dp[0]=nums[0]; dp[1]=max(nums[0],nums[1]); for(int i=2;i<len;i++){ dp[i]=max(dp[i-1],dp[i-2]+nums[i]); } return dp[len-1]; }};
0 0
- House Robber 动态规划
- Leetcode House Robber 动态规划
- [LeetCode][动态规划]House Robber
- 198. House Robber-动态规划
- LeetCode 198. House Robber 213. House Robber II--动态规划
- House Robber 动态规划的使用
- LeetCode 198House Robber动态规划
- leetcode 198.House Robber-打家劫舍|动态规划
- 【Leetcode】198. House Robber - - 【动态规划】
- [LeetCode 198] House Robber(动态规划)
- 【Leetcode】213. House Robber II 【动态规划】
- 198.leetcode House Robber(easy)[动态规划]
- 198. House Robber-leetcode+动态规划
- 动态规划专题之----198. House Robber
- (动态规划)LeetCode#198. House Robber
- leetcode 198. House Robber | 动态规划
- 动态规划解337. House Robber III
- LeetCode 198. House Robber (动态规划)
- fifa 16 coins Points for real-world currency
- Oracle中表被删除或数据被错误修改后的恢复方法
- 【7】Windows客户端C/C++编程规范“建议”——文件
- objective-c 学习笔记一
- MariaDB(mysql)排序诡异问题
- House Robber 动态规划
- Arduino 试用 Digispark Attiny85
- 两个日期时间比较
- TableView和手势冲突解决
- 数据结构与算法分析(c++版) #10 顺序队列
- CSDN停站公告
- 【8】 Windows客户端C/C++编程规范“建议”——变量和常量
- 关于编程过程中空值的判断
- Mina框架并实现Server与Client端的简单消息传递!