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 ...
随机推荐
- Java经典案例之-判断兔子的数量(斐波那契数列)
/** * 描述:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第四个月后每个月又生一对兔子, * 假如兔子都不死,问每个兔子总数为多少? * 分析:根据题目条件可以推断 * 兔子的规律 ...
- php Excel文件导入 Spreadsheet_Excel_Reader
刚刚开通博客,希望能够通过博客的形式记录自己的学习与成长,同时也希望能够和路上的同僚们多交流,共同进步 小白 -> 大神 go! go! go!! 先总结一下前几天写的Excel导入吧,希 ...
- win7配置自己的IIS服务器亲自做的图文很详细
跟人网站爱好初学者必看的win7系统配置自己的IIS,可以在你自己的电脑上配置网站服务器发不到网上,下面就跟着我的步骤一起做吧100%成功. 步骤/方法 点击开始-------控制面板这个就是 ...
- PHP + Memcache 实现Session共享
一.安装Memcache和PHP扩展 Windows下的Memcache安装:1. 下载memcache的windows稳定版,解压放某个盘下面,比如在c:\memcached2. 在终端(也即cmd ...
- doubango(6)--Doubango协议栈中对RTP的管理
相关数据结构 1. tsip_dialog_invite_t 描述: 一个invite_dialog代表了一个invite期间的所有的信令流程,因此,它首先是一个普遍的dialog的特殊化结构, ...
- 在MyEclipse 2014中给Spket增加ExtJS提示
参考:http://wenku.baidu.com/link?url=BT2U6Z-HktQJQYpz3Jp88pJSp4lU-lXkvCqpdeaa9a-BVdOgMGK1vj486-32YC4Gq ...
- SoapUI:入门实例
这一章中我们要掌握如下内容: 1) 构建项目: 2) 运行单个请求: 3) 构建测试用例: 4) 接口之间传递参数,组织测试步骤: 5) ...
- es6笔记6^_^generator
1.简介 Generator函数是一个函数的内部状态的遍历器(也就是说,Generator函数是一个状态机). 形式上,Generator函数是一个普通函数,但是有两个特征. function命令与函 ...
- HDU4403(暴搜)
A very hard Aoshu problem Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- BZOJ-2150部落战争(最小路径覆盖)
2150: 部落战争 Time Limit: 10 Sec Memory Limit: 259 MB Description lanzerb的部落在A国的上部,他们不满天寒地冻的环境,于是准备向A国 ...