UVA 11059 Maximum Product (暴力)


枚举起点与终点即可。

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int t,number,i,j,n,a[20];
	long long ans,max;
	number=0;
	while(scanf("%d",&n)!=EOF) {
		for(i=1;i<=n;i++) scanf("%d",&a[i]);
		max=0;
		for(i=1;i<=n;i++) {
			ans=a[i];
			if(ans>max) max=ans;
			for(j=i+1;j<=n;j++){
				ans*=a[j];
				if(ans>max) max=ans;
			}
		}
		printf("Case #%d: The maximum product is %lld.\n\n",++number,max);
	}
	return 0;
}


你可能感兴趣的:(UVA 11059 Maximum Product (暴力))