1007 Maximum Subsequence Sum (25分)(动态规划DP)

Posted qrain

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1007 Maximum Subsequence Sum (25分)(动态规划DP)相关的知识,希望对你有一定的参考价值。

#include <vector>
#include<iostream>
using namespace std;

int main()
{
    int k;
    cin>>k;
    int left_index=0,right_index=k-1,sum=-1,tmp=0,tmp_index=0;
    vector <int> num(k);
    for(int i=0;i<k;i++)
    {
        cin>>num[i];
        tmp+=num[i];
        if(tmp<0)
        {
            tmp=0;
            tmp_index=i+1;
        }
        else if(tmp>sum)
        {
            sum=tmp;
            left_index=tmp_index;
            right_index=i;
        }
    }
    if(sum<0)
        sum=0;
    cout<<sum<<" "<<num[left_index]<<" "<<num[right_index]<<endl;
    return 0;
}

 https://blog.csdn.net/TOBEALISTENNER/article/details/86667721

以上是关于1007 Maximum Subsequence Sum (25分)(动态规划DP)的主要内容,如果未能解决你的问题,请参考以下文章

1007 Maximum Subsequence Sum(25 分)

1007 Maximum Subsequence Sum

1007. Maximum Subsequence Sum (25)

1007. Maximum Subsequence Sum (25)

1007. Maximum Subsequence Sum (25) 动态规划

1007 Maximum Subsequence Sum (25)(25 分)