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

原文地址:https://www.cnblogs.com/QRain/p/12284488.html

时间: 2024-10-10 12:48:51

1007 Maximum Subsequence Sum (25分)(动态规划DP)的相关文章

1007 Maximum Subsequence Sum (25分) 求最大连续区间和

1007 Maximum Subsequence Sum (25分) Given a sequence of K integers { N?1??, N?2??, ..., N?K?? }. A continuous subsequence is defined to be { N?i??, N?i+1??, ..., N?j?? } where 1≤i≤j≤K. The Maximum Subsequence is the continuous subsequence which has th

[PTA] PAT(A) 1007 Maximum Subsequence Sum (25 分)

目录 Problem Description Input Output Sample Sample Input Sample Output Solution Analysis Code Problem portal: 1007 Maximum Subsequence Sum (25 分) Description Given a sequence of $K$ integers { $N_{1}?$, $N_{2}?$, $...$, $N_{K}$ }. A continuous subsequ

pta 1007 Maximum Subsequence Sum (25分)

Given a sequence of K integers { N?1??, N?2??, ..., N?K?? }. A continuous subsequence is defined to be { N?i??, N?i+1??, ..., N?j?? } where 1. The Maximum Subsequence is the continuous subsequence which has the largest sum of its elements. For exampl

数据结构课后练习题(练习一)1007 Maximum Subsequence Sum (25 分)

Given a sequence of K integers { N?1??, N?2??, ..., N?K?? }. A continuous subsequence is defined to be { N?i??, N?i+1??, ..., N?j?? } where 1. The Maximum Subsequence is the continuous subsequence which has the largest sum of its elements. For exampl

1007 Maximum Subsequence Sum (25 分)

Given a sequence of K integers { N?1??, N?2??, ..., N?K?? }. A continuous subsequence is defined to be { N?i??, N?i+1??, ..., N?j?? } where 1. The Maximum Subsequence is the continuous subsequence which has the largest sum of its elements. For exampl

PTA 1007 Maximum Subsequence Sum (25 分)

1 #include <stdio.h> 2 #include <iostream> 3 #include <string.h> 4 #include <vector> 5 #include <algorithm> 6 #include <cassert> 7 #include <queue> 8 using namespace std; 9 int n; 10 int main() 11 { 12 cin >>

1007 Maximum Subsequence Sum (25)(25 分)

1007 Maximum Subsequence Sum (25)(25 分) Given a sequence of K integers { N~1~, N~2~, ..., N~K~ }. A continuous subsequence is defined to be { N~i~, N~i+1~, ..., N~j~ } where 1 <= i <= j <= K. The Maximum Subsequence is the continuous subsequence

1007. Maximum Subsequence Sum (25)——PAT (Advanced Level) Practise

题目信息: 1007. Maximum Subsequence Sum (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, Ni+1, ..., Nj } where 1 <= i <= j <=

1007. Maximum Subsequence Sum (25)(DP)

Given a sequence of K integers { N1, N2, ..., NK }. A continuous subsequence is defined to be { Ni, Ni+1, ..., Nj } where 1 <= i <= j <= K. The Maximum Subsequence is the continuous subsequence which has the largest sum of its elements. For examp