当前位置:网站首页>Leetcode 1911. maximum subsequence alternating sum
Leetcode 1911. maximum subsequence alternating sum
2022-07-24 20:20:00 【HumbleFool】
LeetCode 1911. Maximum subsequence alternating sum 
State machine DP
typedef long long LL;
const int N = 1e5 + 10;
class Solution {
public:
LL f[N][2]; //f[i][0] Before presentation i Choose the maximum sum of even numbers ,f[i][1] Before presentation i Select the maximum sum of odd numbers
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]);
}
};
边栏推荐
- Analysis of xmldecoder parsing process
- Login Huawei device in SSH mode
- Each blogger needs to ask himself seven basic questions
- Mysql8 doesn't seem to support MyISAM partition tables. Does polardb-x support MyISAM partition tables?
- Alibaba cloud technology expert Yang Zeqiang: building observable capabilities on elastic computing cloud
- Decorator of function
- What is IDE (integrated development environment)
- [training Day8] [luogu_p6335] staza [tarjan]
- MySQL advanced 2
- [msp430g2553] graphical development notes (1) configuration environment
猜你喜欢

Pix2seq: Google brain proposes a unified interface for CV tasks!

Usage and introduction of MySQL binlog

Introduction to fastdfs high availability

Read the registry through the ATL library clegkey (simple and convenient)
![[FreeRTOS] 10 event flag group](/img/c3/9f9c2ac4641f478575d48afd580b4b.png)
[FreeRTOS] 10 event flag group

Setting up a dual machine debugging environment for drive development (vs2017)

Redis basic knowledge, application scenarios, cluster installation

聊下自己转型测试开发的历程

147-利用路由元信息设置是否缓存——include和exclude使用——activated和deactivated的使用

English grammar_ Demonstrative pronoun this / these / that / those
随机推荐
870. Approximate number
Expression evaluation (stack)
Lunch break train & problem thinking: on multidimensional array statistics of the number of elements
1. Mx6u-alpha development board (key input experiment)
[msp430g2553] graphical development notes (1) configuration environment
Write a batch and start redis
Safe way -- Analysis of single pipe reverse connection back door
[training Day9] light tank [dynamic planning]
Batch download files from the server to the local
Do you want to enroll in a training class or study by yourself?
Azide labeled PNA peptide nucleic acid | methylene blue labeled PNA peptide nucleic acid | tyrosine modified PNA | Tyr PNA Qiyue Bio
Istio二之流量劫持过程
"Six pillars of self esteem" self esteem comes from one's own feelings
[training Day10] point [enumeration] [bidirectional linked list]
Stop using UUID indiscriminately. Have you tested the performance gap between self incrementing ID and UUID?
Call Baidu AI open platform to realize image and character recognition
Near infrared dye cy7.5 labeling PNA polypeptide experimental steps cy7.5-pna|188re labeling anti gene peptide nucleic acid (agpna)
The beginning of winter in the year of bitterness and ugliness
PD user manual
Mysql8 doesn't seem to support MyISAM partition tables. Does polardb-x support MyISAM partition tables?