需要注意的情况:
1.全是负数 (题干:If all the K numbers are negative, then its maximum sum is defined to be 0, and you are supposed to output the first and the last numbers of the whole sequence.)
输出 0 第一个数 最后一个数
2.负数和0
输出 0 0 0
这是按照正常的求最大子列和的方法得到的结果,因为初始化maxsum=0,后面循环中因为都是负数或0不会比它大,所以maxsum值不会更新,为0。在MaxSubSeq函数里输出时单独输出这个maxsum=0的特殊情况。
原题:
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 example, given sequence { -2, 11, -4, 13, -5, -2 }, its maximum subsequence is { 11, -4, 13 } with the largest sum being 20.
Now you are supposed to find the largest