最大乘积连续子串
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
double func(double *a,const int n){
double dp[2]={0},maxv = a[0];
dp[0] = a[0];
for(int i = 1; i < n; i ++ ){
dp[i%2] = max(a[i],dp[(i-1)%2]*a[i]);
maxv=max(maxv,dp[i%2]);
}
return maxv;
}
int main(){
double a[]={-2.5,4,0,3,0.5,8,-1};
cout<<func(a,7)<<endl;
return 0;
}

浙公网安备 33010602011771号