当前位置:网站首页>LeetCode 1911. 最大子序列交替和
LeetCode 1911. 最大子序列交替和
2022-07-21 06:40:00 【HumbleFool】
typedef long long LL;
const int N = 1e5 + 10;
class Solution {
public:
LL f[N][2]; //f[i][0]表示前i个选偶数个的最大和,f[i][1]表示前i个选奇数个的最大和
long long maxAlternatingSum(vector<int>& nums) {
int n = nums.size();
f[0][0] = 0;
for(int i = 1; i <= n; i ++)
{
f[i][0] = max(f[i - 1][0], f[i - 1][1] + nums[i - 1]);
f[i][1] = max(f[i - 1][1], max(0LL, f[i - 1][0] - nums[i - 1]));
}
return max(f[n][0], f[n][1]);
}
};
边栏推荐
- Leetcode skimming 03
- How to start your online life
- 如何测试webservice接口
- What is the new generation of enterprise IT architecture? Cloud primordial? Low code?
- Centos7 online MySQL installation
- Web automation processing "sliding verification code"
- Selenium被检测为爬虫,怎么屏蔽和绕过
- 子网掩码的作用
- Lecture 1 Overview
- Interpreting the maker education model in line with the mainstream of the new era
猜你喜欢
随机推荐
查看IAR工程所用版本号
百度工程师眼中的云原生可观测性追踪技术
牛客刷题 01——KiKi去重整数并排序(C语言)
Software resources Encyclopedia
Houdini楼房刚体区域影响破碎笔记
[data analysis 02]
[daily training] 1260 2D mesh migration
uniapp 使用 u-view 框架小程序的样式问题集合
Class template overload output operator error
如何测试webservice接口
接口测试中,要验证和使用数据库吗
MongoDB 中的管道操作符($group、$unwind、$sort、$limit、$skip)
About object obj = new object()
Diffusion Model
List parsing < STL elementary > (runner's notes)
"Core engine" of Technology
Chrome实现自动化测试:录制回放网页动作
Word 2016 strange problem: file save error copy crash
20220719 adapt openharmony-v3.1-beta to aio-3568j
多线程一定能优化程序性能吗?