int Left
,Right
;
int MaxSubsequenceSum(int a
[],int N
)
{
int sum
=0; int maxsum
=0;
Left
=0;Right
=N
-1;
int count
=0;
for(int i
=0;i
<N
;i
++){
sum
+=a
[i
];
count
++;
if(maxsum
<sum
){
maxsum
=sum
;
Right
=i
;
Left
=Right
-count
+1;
}
else if(sum
<0) {sum
=0;count
=0;}
else if(sum
==0){
if(i
<Right
){
Right
=i
;Left
=Right
;}
}
return maxsum
;
}
转载请注明原文地址: https://yun.8miu.com/read-136598.html