其他分享
首页 > 其他分享> > [AcWing 1058] 股票买卖 V

[AcWing 1058] 股票买卖 V

作者:互联网

image
image


点击查看代码
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

const int N = 1e5 + 10;

int n;
int a[N];
int f[N][3];

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i ++)
        cin >> a[i];
    memset(f, -0x3f, sizeof f);
    f[0][0] = 0;
    for (int i = 1; i <= n; i ++) {
        f[i][0] = max(f[i - 1][0], f[i - 1][2]);
        f[i][1] = max(f[i - 1][1], f[i - 1][0] - a[i]);
        f[i][2] = f[i - 1][1] + a[i];
    }
    cout << max(f[n][0], f[n][2]) << endl;
    return 0;
}

  1. 状态机模型

标签:std,股票买卖,main,const,1058,状态机,int,include,AcWing
来源: https://www.cnblogs.com/wKingYu/p/16410301.html