C难题 求解,关于数据结构!求高手 递归
int maxsubsum(const int a[],int left,int right){
int maxleftsum,maxrightsum;
int leftbordersum,rightbordersum;
int maxleftbordersum,maxrightbordersum;
int center,i;
if(left==right)
if(a[left]>0)
return a[left];
else return 0;
center=(left+right)/2;
maxleftsum=maxsubsum(a,left,center);
maxrightsum=maxsubsum(a,center+1,right);这个递归弄不懂,求高手指点一二
leftbordersum=0;
rightbordersum=0;
maxleftbordersum=0;
maxrightbordersum=0;
for(i=center;i>=left;i--){
leftbordersum+=a[i];
if(leftbordersum>maxleftbordersum)
maxleftbordersum=leftbordersum;}
for(i=center+1;i<=right;i++){
rightbordersum+=a[i];
if(rightbordersum>maxrightbordersum)
maxrightbordersum=rightbordersum;}
return max3(maxleftsum,maxrightsum,maxleftbordersum+maxrightbordersum);
}
int maxsubsequence2(const int a[],int n)
{
return maxsubsum(a,0,n-1);
}