Main topic:
That is to give you n numbers, and then to find out the maximum and the continuous sequence. If ANS is negative, the output is 0, or the ANS is output.
Problem Solving Ideas:
In fact, we just need to enumerate the starting point and the end point, and then consider all the circumstances, a bit similar to solving the problem of maximum continuity.
The only difference is to initialize T = 1, t*=a[j] every time. Note Long long. Because there are up to 18 numbers, and each number
The maximum value is 10, then their product will not exceed 10^18.
Code:
# include<cstdio># include<iostream># include<algorithm># include<functional># include<cstring># include<string># include<cstdlib># include<iomanip># include<numeric># include<cctype># include<cmath># include<ctime># include<queue># include<stack># include<list># include<Set># include<map>using namespacestd;Const DoublePi=4.0*atan (1.0); typedefLong Longll;typedef unsignedLong Longull;# define INF999999999# define MAX atintA[max];intN;intMainvoid){ intIcase =1; while(cin>>N) { for(inti =1; I <= n;i++) {cin>>A[i]; } LL ans=0; for(inti =1; I <= n;i++) {LL T=1; //ans = max (ans,t); for(intj = I;j <= n;j++) {T*=A[j]; Ans=Max (ans,t); }} printf ("Case #%d:the Maximum product is%lld.\n\n", icase++, ans); } return 0;}View Code
UVA 11059 Maximum Product (enumeration start+end)