文章目录
蛮力分治迭代:一遍扫描
蛮力
改进
分治
迭代:一遍扫描
#include<vector>
#include<iostream>
using namespace std
;
int fun1(int A
[],int n
);
int main(){
int array
[5]={-5,1,-1,1,-10};
cout
<<fun1(array
,5)<<endl
;
return 0;
}
int fun1(int A
[],int n
){
int gs
=A
[0],s
=0,i
=n
,j
=n
;
while(0<i
--){
s
+=A
[i
];
if(gs
<s
) gs
=s
;
if(s
<=0){s
=0;j
=i
;}
}
return gs
;
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-7630.html