最大子序列和

算法4(联机算法on-line algorithm)

int MaxSubsequenceSum(const int A[],int count)
{
    int ThisSum = 0, MaxSum = 0;
    for (int i = 0; i < count; i++)
    {
        ThisSum += A[i];

        MaxSum = ThisSum > MaxSum ? ThisSum : MaxSum;
        if (ThisSum < 0)
            ThisSum = 0;
    }
    return MaxSum;
}

 

你可能感兴趣的:(最大子序列和)