Housse Robber II | leetcode
可以复用house robber的代码,两趟dp作为两种情况考虑,选最大值
#include <stdio.h>
#define MAX 1000
#define max(a,b) ( (a)>(b)?(a):(b) )
int dp[MAX]={};
int rob1(int* a, int n) {
int i;
dp[]=;
dp[]=a[];
for(i=;i<n;i++){
dp[i+]=max(dp[i],a[i]+dp[i-]);
}
return dp[n];
} int rob(int* nums, int numsSize) {
if(numsSize==)return nums[];
return max(rob1(nums,numsSize-),rob1(nums+,numsSize-)) ;
}
Housse Robber II | leetcode的更多相关文章
- House Robber II——Leetcode
After robbing those houses on that street, the thief has found himself a new place for his thievery ...
- [LeetCode]House Robber II (二次dp)
213. House Robber II Total Accepted: 24216 Total Submissions: 80632 Difficulty: Medium Note: Thi ...
- LeetCode之“动态规划”:House Robber && House Robber II
House Robber题目链接 House Robber II题目链接 1. House Robber 题目要求: You are a professional robber planning to ...
- 【LeetCode】213. House Robber II
House Robber II Note: This is an extension of House Robber. After robbing those houses on that stree ...
- 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:二叉树下的不能相邻,求能 ...
- 【刷题-LeetCode】213. House Robber II
House Robber II You are a professional robber planning to rob houses along a street. Each house has ...
- [LintCode] House Robber II 打家劫舍之二
After robbing those houses on that street, the thief has found himself a new place for his thievery ...
- 198. House Robber,213. House Robber II
198. House Robber Total Accepted: 45873 Total Submissions: 142855 Difficulty: Easy You are a profess ...
- Path Sum II - LeetCode
目录 题目链接 注意点 解法 小结 题目链接 Path Sum II - LeetCode 注意点 不要访问空结点 解法 解法一:递归,DFS.每当DFS搜索到新节点时,都要保存该节点.而且每当找出一 ...
随机推荐
- 重拾ZOJ 一周解题
ZOJ 2734 Exchange Cards 题目大意: 给定一个值N,以及一堆卡片,每种卡片有一个值value和数量number.求使用任意张卡片组成N的方式. 例如N = 10 ,cards(1 ...
- 初始化lpc2106开发工程
单片机型号:lpc2106.Init.s:初始化pc指针和sp指针. AREA Init, CODE, READONLY IMPORT test1_main EXPORT ...
- java多次替换(replace不行)
import java.util.regex.Matcher; import java.util.regex.Pattern; public class test { public static vo ...
- java Android SDK安装与环境变量配置以及开发第一个Android程序
JAVA的安装与环境变量的配置 1.先下载JAVA,并且安装. 下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk-7u3 ...
- C#泛类型链表的实现
使用泛型LinkedList<T>类.下面的方法创建了一个LinkedList<T>类,并往链表对象中添加节点,然后使用了几种方法从链表节点中获得信息. publi ...
- 【BZOJ】1069: [SCOI2007]最大土地面积(凸包+旋转卡壳)
http://www.lydsy.com/JudgeOnline/problem.php?id=1069 显然这四个点在凸包上,然后枚举两个点找上下最大的三角形即可. 找三角形表示只想到三分QAQ.. ...
- Linux压力测试工具
1 http_load:http://www.oschina.net/p/http_load 命令行输入man http_load 或者 http_load -h可以看到工具的使用方式: 参数说明: ...
- 细说LastLogonTimeStamp
微软在Windows Server 2003中引入了LastLogonTimeStamp属性.管理员们可以利用这个属性查看用户或者计算机最近是否登录过域.根据这些信息,管理员可以对长时间没有登录的账户 ...
- HP StorageWorks MSL2024 Tape Libraries - Tape library Error Codes
Main error codes Error Code Description Details and Solution 80 Can not initialize bar code reader P ...
- html5_d登陆界面_注册界面
<!DOCTYPE html><html><head><script type="text/javascript">function ...