对于连续子序列问题,如果数据范围小的话,可以枚举起点和终点。
1 #include <iostream> 2 #include <cstring> 3 #include <string> 4 #include <map> 5 #include <set> 6 #include <algorithm> 7 #include <fstream> 8 #include <cstdio> 9 #include <cmath> 10 #include <stack> 11 #include <queue> 12 using namespace std; 13 const double Pi=3.14159265358979323846; 14 typedef long long ll; 15 const int MAXN=5000+5; 16 const int dx[5]={0,0,0,1,-1}; 17 const int dy[5]={1,-1,0,0,0}; 18 const int INF = 0x3f3f3f3f; 19 const int NINF = 0xc0c0c0c0; 20 const ll mod=1e9+7; 21 int a[100]; 22 int main() 23 { 24 int n;int cnt=0; 25 while(cin>>n) 26 { cnt++; 27 for(int i=1;i<=n;i++) 28 scanf("%d",&a[i]); 29 ll maxn=0; 30 for(int i=1;i<=n;i++) 31 { 32 for(int j=i;j<=n;j++) 33 { 34 ll sum=1; 35 for(int k=i;k<=j;k++) 36 { 37 sum*=a[k]; 38 } 39 if(sum>maxn) maxn=sum; 40 } 41 } 42 printf("Case #%d: The maximum product is %lld.\n\n",cnt,maxn); 43 } 44 return 0; 45 }