当前位置:网站首页>198. Looting - Dynamic Planning
198. Looting - Dynamic Planning
2022-07-03 18:19:00 【The_ Dan】
class Solution {
public:
int rob(vector<int>& nums) {
int ans = 0;
int n = nums.size();
if(n == 1) // A special case : Only 1 Elements
return nums[0];
if(n == 2) // A special case : Only 2 Elements
return max(nums[0], nums[1]);
int dp[n];
dp[0] = nums[0]; //dp[1] It's the first element
dp[1] = max(nums[0], nums[1]); //dp[2] Is the larger of the first two elements
for(int i = 2; i < n; i++){
// The popular formula is , Intrinsic value + Previous And Compare with the previous
dp[i] = max(dp[i - 1], dp[i - 2] + nums[i]);
}
return dp[n - 1];
}
};
Accepted
68/68 cases passed (0 ms)
Your runtime beats 100 % of cpp submissions
Your memory usage beats 73.66 % of cpp submissions (7.4 MB)
边栏推荐
- Summary and Reflection on the third week of winter vacation
- Redis on local access server
- Distributed task distribution framework gearman
- How to expand the capacity of golang slice slice
- Three gradient descent methods and code implementation
- Discussion sur la logique de conception et de mise en oeuvre du processus de paiement
- Module 9 operation
- Postfix 技巧和故障排除命令
- Use of unsafe class
- 【统信UOS】扫描仪设备管理驱动安装
猜你喜欢

Research Report on market demand and investment planning for the development of China's office chair industry, 2022-2028

Redis cache avalanche, penetration, breakdown

PHP MySQL preprocessing statement

How to draw non overlapping bubble chart in MATLAB

English語法_名詞 - 分類

win32:堆破坏的dump文件分析

基于人脸识别的课堂考勤系统 tkinter+openpyxl+face_recognition

Redis core technology and practice - learning notes (IX): slicing cluster

Codeforces Round #803 (Div. 2) C. 3SUM Closure

Should I be laid off at the age of 40? IBM is suspected of age discrimination, calling its old employees "dinosaurs" and planning to dismiss, but the employees can't refute it
随机推荐
English语法_形容词/副词3级 - 倍数表达
How to track the real-time trend of Bank of London
Redis core technology and practice - learning notes (VIII) sentinel cluster: sentinel hung up
Solve the problem of inaccurate network traffic monitored by ZABBIX with SNMP
网格图中递增路径的数目[dfs逆向路径+记忆dfs]
圖像24比特深度轉8比特深度
小程序 多tab 多swiper + 每个tab分页
[tutorial] build your first application on coreos
As soon as we enter "remote", we will never regret, and several people will be happy and several people will be sad| Community essay solicitation
The second largest gay dating website in the world was exposed, and the status of programmers in 2022
This diversion
ES7 - Optimization of promise
MySQL grouping query
[combinatorics] generating function (positive integer splitting | repeated ordered splitting | non repeated ordered splitting | proof of the number of repeated ordered splitting schemes)
Computer graduation design PHP makeup sales Beauty shopping mall
PHP MySQL where clause
English语法_名词 - 分类
Enterprise custom form engine solution (12) -- form rule engine 2
[Yu Yue education] family education SPOC class 2 reference materials of Shanghai Normal University
[combinatorics] generating function (summation property)