国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

198. House Robber

2019-11-06 06:17:36
字體:
來源:轉載
供稿:網友

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. 思路:動態規劃,這個和幣值最大化問題一樣的狀態轉移方程 F(n) = max(c + F(n - 2), F(n - 1)), n > 1

class Solution {public: int rob(vector<int>& nums) { int size = nums.size(); int *F = new int[size]; if(size == 0) return 0; else if(size == 1) return nums[0]; F[0] = nums[0], F[1] = max(nums[0], nums[1]); for(int i = 2; i < size; ++i){ F[i] = max(nums[i] + F[i - 2], F[i - 1]); } return F[size - 1]; }};
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 稻城县| 潞西市| 六枝特区| 临沧市| 南安市| 屏东县| 祁连县| 大田县| 蕲春县| 威海市| 双桥区| 湟源县| 饶阳县| 武宣县| 昭通市| 句容市| 白河县| 黎川县| 乌鲁木齐市| 遂川县| 布尔津县| 阿巴嘎旗| 绵竹市| 曲阳县| 龙口市| 仙游县| 嘉禾县| 兴山县| 通山县| 绍兴县| 临泉县| 三门县| 潼南县| 澄城县| 深州市| 建瓯市| 囊谦县| 诸暨市| 东安县| 桑植县| 孟津县|