最大子序列和问题问题描述:给定一个整数序列,a0, a1, a2, …… , an(项可以为负数),求其中最大的子序列和。如
最大子序列和问题
问题描述:
int maxSubSum3_4( const vector<int> &a ) { int maxSum = 0; int thisSum = 0; for(int j=0; j<a.size(); j++ ) { thisSum += a[j]; if(thisSum>maxSum) { maxSum = thisSum; } else if( thisSum>0 ) { //do nothing } else if( thisSum < 0 ) { thisSum = 0; } } return maxSum; }分析:
