leetcode HouseRobber Dp Code
#include <malloc.h>
int MAX(int x,int y){
return x>y?x:y;
}
int rob(int* nums, int numsSize) {
int *m;
int i;
m = (int *)malloc(sizeof(int)*(numsSize+1));
m[0] = 0;
m[1] = nums[0];
m[2] =MAX(nums[0],nums[1]);
for(i=3;i<=numsSize;i++){
m[i] = MAX(m[i-1],nums[i-1]+m[i-2]);
}
return m[numsSize];
}
初学dp,终于能写出一个dp水题了,也算是提升吧
leetcode HouseRobber Dp Code的更多相关文章
- leetcode distinct-subsequences(DP)
参考https://oj.leetcode.com/problems/distinct-subsequences 动态规划方程 dp[i][j]=dp[i-1][j-1]+dp[i-1][j] (s( ...
- [LeetCode] Unique Morse Code Words 独特的摩斯码单词
International Morse Code defines a standard encoding where each letter is mapped to a series of dots ...
- [LeetCode] 89. Gray Code 格雷码
The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...
- 【LeetCode】Gray Code
Gray Code The gray code is a binary numeral system where two successive values differ in only one bi ...
- 【leetcode】Gray Code (middle)
The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...
- 【题解】【排列组合】【回溯】【Leetcode】Gray Code
The gray code is a binary numeral system where two successive values differ in only one bit. Given a ...
- [Leetcode][Python][DP]Regular Expression Matching
# -*- coding: utf8 -*-'''https://oj.leetcode.com/problems/regular-expression-matching/ Implement reg ...
- leetcode[88] Gray Code
题目:格雷码. 格雷码是从0开始且之后两个相邻码之间只有一个符号不相同,例如000,100,101,111三个相邻之间只有一个二进制不同. 现在给定一个数字n,然后给出格雷码所对应的数字.例如: Fo ...
- Leetcode:【DP】Longest Palindromic Substring 解题报告
Longest Palindromic Substring -- HARD 级别 Question SolutionGiven a string S, find the longest palindr ...
随机推荐
- iOS NSTimer
示例: //创建 scrollTimer =[NSTimer scheduledTimerWithTimeInterval:interval target:self selector:@selecto ...
- Hybird应用开发实践(一)使用原生/cordova混合项目
最近准备尝试hybird开发原生应用,因为公司的项目本来就是原生开发的,所以准备选择cordova作为webview嵌入原生项目的开发方式.这里就以mac上整合ios项目为例. 1. 创建cordov ...
- MongoDB安装环境搭建
Mongodb的默认端口号27017 _id是全局唯一值,不要去给这个列赋值,默认是唯一的,如果赋值,列入有两列的_id:2,则会报冲突不能插入 [root@HE4 ~]# tar xvf mongo ...
- flex blazeds地址
flex blazeds地址 BlazeDS地址:http://sourceforge.net/adobe/blazeds/wiki/Home/最新BlazeDS版本是2011年编译的4.0.1.21 ...
- 基于ssh反向代理实现的远程协助
本文描述了怎么通过ssh反向代理实现远程协助,并提供了相关代码. 可满足web开启远程协助功能后,维护人员能够通过ssh和http登录客户机器(包括在nat环境下) web开启该功能后,ssh才能登录 ...
- Swift2.2 看完这篇博客 你不想懂也会懂得----二叉树
一:初衷 我自己也好奇,为什么莫名其妙的想起写这个,其实数据里面包含的结构和逻辑我自己觉得才是最原始经典的,最近也在学swift,就向着利用swift整理一些二叉树.自己刚开始的时候也是用OC看着别的 ...
- C语言 extern3 全局变量的使用
和函数的全局使用极其类似: 第一种方法,也是最简单的: 在 first.h 中定义, ; 在对应的first.c中使用: #include "first.h" #include & ...
- VS编辑器主题变换插件-EasyVS
主题功能是这个版本的亮点. 我收集了七个比较流行的编辑器主题样式,有了这个功能再也不用到网上寻找安装这样那样的主题了. 增加文件右键“在资源管理器中打开”功能 我们知道VS2010对文件夹支持“在资源 ...
- SpringMVC总结的部分教程及使用方法
注:本文只用注解来实现 SpringMVC各种流程图流程图(其他的各种流程图)jsp.xml.action彼此之间的关系,都如何使用spring-mvc.xml如何配置,放在哪里?action中如何转 ...
- 【Java深入研究】2、JVM类加载机制
一.先看看编写出的代码的执行过程: 二.研究类加载机制的意义 从上图可以看出,类加载是Java程序运行的第一步,研究类的加载有助于了解JVM执行过程,并指导开发者采取更有效的措施配合程序执行. 研究类 ...