Description:

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.

求数组中不相邻两个数组合的最大值。

ps.难道这就是传说中的DP

public class Solution {
public int rob(int[] nums) { if(nums.length == 0)
return 0;
if(nums.length == 1)
return nums[0];
if(nums.length == 2)
return Math.max(nums[0], nums[1]);
int[] res = new int[nums.length];
res[0] = nums[0];
res[1] = nums[1];
res[2] = nums[0] + nums[2];
for(int i=3; i<nums.length; i++) {
res[i] = Math.max(res[i-2],res[i-3]) + nums[i];
}
return Math.max(res[nums.length-1], res[nums.length-2]);
}
}

最新文章

  1. 安装Adobe系列时遇到的问题解决
  2. eclipse有时候会报错:Cannot change version of project facet Dynamic Web Module to 2.5。这个错误不会影响程序的运行,不过看着总是不舒服。这个问题现在可以解决啦。
  3. asp实现关键词不区分大小写搜索并高亮显示
  4. animation css3动画与CSS3 @keyframes担配使用创建往复平缓动画
  5. 使用带Arduino IDE &amp; WIZ820io的ATmega1284P
  6. 插件的理解$.extend()与$.fn.extend()
  7. 图解C#_事件
  8. 蓝桥杯-第一个数字-java
  9. 第65章 博客帖子 - Identity Server 4 中文文档(v1.0.0)
  10. centos7.1安装tomcat8
  11. (整理)SQL Server 2008 CDC 功能使用
  12. Java基础知识中的注意事项
  13. Linux 流量监控工具 iftop
  14. 获取RadioButton选中的值
  15. Unity3D学习笔记(三十四):Shader着色器(1)
  16. C++ socket 网络编程 简单聊天室
  17. CorelDRAW X7绘制可爱的卡通动漫多啦A梦
  18. 托管调试助手 &quot;DisconnectedContext&quot;:“上下文 0xf20540 已断开连接... 请确保在应用程序全部完成 RuntimeCallableWrapper (表示其内部的 COM 组件)之前,所有 COM 上下文/单元/线程都保持活动状态并可用于上下文转换
  19. Noip前的大抱佛脚----图论
  20. 有趣的 Mysql 存储引擎

热门文章

  1. Ubuntu 下查看中文man手册方法
  2. 【springmvc笔记】第二课 环境搭建和第一个springmvc例子
  3. 【大数据笔记】白话详解Zookeeper的一致性
  4. /dev/sdxx is apparently in use by the system; will not make a filesystem here! 解决方法
  5. SGU 120 Archipelago (简单几何)
  6. 基于Python的测试驱动开发实战
  7. EXTJS入门教程及其框架搭建
  8. 15天玩转redis(mark,redis学习系列)
  9. 关于Cocos2d-x对象的定义和创建
  10. bowtie2-inspect 根据bowtie2的索引取得fasta 序列