int find_Max_mumSubarray(int a[],int n,int &low,int &high){
int max_sum=a[0];
for(int i=0;i<n;i++){
int sum=0;
for(int j=i;j<n;j++){
sum=sum+a[j];
if(sum>max_sum){
low=i;
high=j;
max_sum=sum;
}
}
}
return max_sum;
}
int main( )
{
int a[]={13,-3,-25,20,-3,-16,-23,18,20,-7,12,-5,-22,15,-4,7};
int low,high;
cout<<low<<" "<<high<<" "<<find_Max_mumSubarray(a,16,low,high);
return 0;
}
算法复杂度 O(n^2)
算法学习笔记--暴力求解最大子数组
最新推荐文章于 2023-04-16 22:53:18 发布