当前位置:网站首页>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)
边栏推荐
- Global and Chinese pediatric palliative care drug market development research and investment planning recommendations report 2022-2028
- Global and Chinese health care OEM and ODM market status survey and investment planning recommendations report 2022-2028
- Five problems of database operation in commodity supermarket system
- Golang string (string) and byte array ([]byte) are converted to each other
- PHP MySQL where clause
- List的stream中Long对象与long判等问题记录
- 【统信UOS】扫描仪设备管理驱动安装
- Gear2021 monthly update - December
- How to draw non overlapping bubble chart in MATLAB
- Discussion sur la logique de conception et de mise en oeuvre du processus de paiement
猜你喜欢

2022-2028 global lithium battery copper foil industry research and trend analysis report

Research Report on investment trends and development planning of China's thermal insulation material industry, 2022-2028

Redis core technology and practice - learning notes (VIII) sentinel cluster: sentinel hung up

Getting started with deops

What kind of experience is it when the Institute earns 20000 yuan a month?

An academic paper sharing and approval system based on PHP for computer graduation design
![网格图中递增路径的数目[dfs逆向路径+记忆dfs]](/img/57/ff494db248171253996dd6c9110715.png)
网格图中递增路径的数目[dfs逆向路径+记忆dfs]

Naoqi robot summary 27

2022-2028 global scar care product industry research and trend analysis report

模块九作业
随机推荐
G1 garbage collector of garbage collector
Class exercises
Mature port AI ceaspectus leads the world in the application of AI in terminals, CIMC Feitong advanced products go global, smart terminals, intelligent ports, intelligent terminals
OpenSSL的SSL/BIO_get_fd
Global and Chinese pediatric palliative care drug market development research and investment planning recommendations report 2022-2028
Redis core technology and practice - learning notes (VI) how to achieve data consistency between master and slave Libraries
Fedora 21 安装 LAMP 主机服务器
How to analyze the rising and falling rules of London gold trend chart
How do microservices aggregate API documents? This wave of operation is too good
WebView module manages the application window interface to realize the logical control and management operation of multiple windows (Part 1)
聊聊支付流程的設計與實現邏輯
Redis cache avalanche, penetration, breakdown
Win 11 major updates, new features love love.
Distributed task distribution framework gearman
[combinatorics] generating function (summation property)
Niuke monthly race 31 minus integer
统计图像中各像素值的数量
[tutorial] build your first application on coreos
PHP MySQL reads data
supervisor监控Gearman任务