198. House Robber(Array; DP)
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.
class Solution {
public:
int rob(vector<int>& nums) {
int size = nums.size();
if(size == ) return ;
if(size == ) return nums[]; vector<int> maxMoney(size,); //save the max robbed money until now
maxMoney[] = nums[];
maxMoney[] = max(nums[],nums[]);
for(int i = ; i < size; i++){
maxMoney[i] = max(maxMoney[i-]+nums[i], maxMoney[i-]);
} return maxMoney[size-];
}
};
198. House Robber(Array; DP)的更多相关文章
- 198. House Robber,213. House Robber II
198. House Robber Total Accepted: 45873 Total Submissions: 142855 Difficulty: Easy You are a profess ...
- 198. House Robber(动态规划)
198. House Robber You are a professional robber planning to rob houses along a street. Each house ha ...
- leetcode 198. House Robber 、 213. House Robber II 、337. House Robber III 、256. Paint House(lintcode 515) 、265. Paint House II(lintcode 516) 、276. Paint Fence(lintcode 514)
House Robber:不能相邻,求能获得的最大值 House Robber II:不能相邻且第一个和最后一个不能同时取,求能获得的最大值 House Robber III:二叉树下的不能相邻,求能 ...
- Educational Codeforces Round 56 (Rated for Div. 2) F - Vasya and Array dp好题
F - Vasya and Array dp[ i ][ j ] 表示用了前 i 个数字并且最后一个数字是 j 的方案数. dp[ i ][ j ] = sumdp [i - 1 ][ j ], 这样 ...
- [LeetCode] 198. House Robber 打家劫舍
You are a professional robber planning to rob houses along a street. Each house has a certain amount ...
- Leetcode 198 House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount ...
- Java for LeetCode 198 House Robber
You are a professional robber planning to rob houses along a street. Each house has a certain amount ...
- 198. House Robber
题目: You are a professional robber planning to rob houses along a street. Each house has a certain am ...
- [LeetCode] 198. House Robber _Easy tag: Dynamic Programming
You are a professional robber planning to rob houses along a street. Each house has a certain amount ...
随机推荐
- leetcode1019
class Solution(object): def nextLargerNodes(self, head: ListNode) -> 'List[int]': n = 0 temp = he ...
- PHPExcel在TP下使用
第一:你要去PHPExcel官网下载,然后放到网站的Vendor文件夹下面.当然这是为了好管理和导入.你放在其他位置也没有关系. 第二:当然是在你需要的地方写代码.我只写样例,你看懂了就可以灵活的使用 ...
- [转] golang socket
server.go package main import ( "net" "fmt" "io/ioutil" "time&quo ...
- 机器学习入门-文本特征-使用LDA主题模型构造标签 1.LatentDirichletAllocation(LDA用于构建主题模型) 2.LDA.components(输出各个词向量的权重值)
函数说明 1.LDA(n_topics, max_iters, random_state) 用于构建LDA主题模型,将文本分成不同的主题 参数说明:n_topics 表示分为多少个主题, max_i ...
- day05-表的三种关系
表的三种关系 1)一对一 关联方式:foreign key+unique例如1个学生只能有1个学号,1个学号只能对应1个学生 #两张表: 学生表(student)和 学号表(student_id) # ...
- How to install Redis 3.2 on CentOS 6 and 7
What is Redis? Redis is a flexible open-source, key value data store, used as a database, cache and ...
- C# 利用反射调用类下的方法
namespace TestReflection { public partial class Form1 : Form { public Form1() { InitializeComponent( ...
- 2319__1.5.3 Superprime Rib 特殊的质数肋骨
[Submit][Status][Forum] Description 农民约翰母牛总是产生最好的肋骨. 你能通过农民约翰和美国农业部标记在每根肋骨上的数字认出它们. 农民约翰确定他卖给买方的是真正的 ...
- Zabbix3.0版Graphtree的安装配置
Graphtrees: https://github.com/OneOaaS/graphtrees 如果是采用yum安装的zabbix-server, 则使用以下方式: # mv /usr/shar ...
- eclipse无法加载主类错误(项目上红色感叹号问题解决)
在用eclipse运行一个简单的继承程序时,在点击运行时提示如下: 点击process后,提示无法加载主类错误 在网上一直没找到原因,连helloword程序都无法正常运行了,而且此时我看到文件项目中 ...