第七章部分例題最大乘積
阿新 • • 發佈:2017-08-21
創建 max 第七章 blog 例題 pac ons std esp
思路:用數組存儲
然後枚舉起點和終點來創建子序列由於乘積很大所以要用long long 同時使用cout輸出避免printf不同編譯器的不同實現
1 #include <cstdio> 2 #include <algorithm> 3 #include <iostream> 4 5 using namespace std; 6 7 long long const inf=-1e18; 8 int s[20]; 9 10 int main() 11 { 12 long long mu; 13 long long best=inf;14 15 cout<<best<<endl; 16 17 int n; 18 cin>>n; 19 20 for(int i=0;i<n;i++) 21 scanf("%d",&s[i]); 22 23 for(int i=0;i<n;i++) 24 for(int j=n-1;j>=i;j--) 25 { 26 mu=1; 27 28 for(int b=i;b<=j;b++) 29 mu*=s[b];30 31 best=max(best,mu); 32 } 33 34 cout<<best<<endl; 35 }
第七章部分例題最大乘積