【题意】给出一个序列,问这个序列中最大连续累乘的子序列中,最大的值为多少,如果都为负数,则输出。
【解题方法】整个元素最多有18个,大小最大10.所以要开到long long。然后列举所有长度即可。
【AC代码】
//
//Created by just_sort 2016/1/3
//Copyright (c) 2016 just_sort.All Rights Reserved
//
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/hash_policy.hpp>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdio>
#include <time.h>
#include <cstdlib>
#include <cstring>
#include <sstream> //isstringstream
#include <iostream>
#include <algorithm>
using namespace std;
using namespace __gnu_pbds;
typedef long long LL;
typedef pair<int, LL> pp;
#define REP1(i, a, b) for(int i = a; i < b; i++)
#define REP2(i, a, b) for(int i = a; i <= b; i++)
#define REP3(i, a, b) for(int i = a; i >= b; i--)
#define CLR(a, b) memset(a, b, sizeof(a))
#define MP(x, y) make_pair(x,y)
const int maxn = 100;
const int maxm = 2e5;
const int maxs = 10;
const int INF = 1e9;
const int UNF = -1e9;
const int mod = 1e9+7;
int gcd(int x, int y) {return y == 0 ? x : gcd(y, x % y);}
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>order_set;
//head
LL a[20];
int main()
{
int n, ks = 0;
while(scanf("%d", &n) != EOF)
{
REP2(i, 1, n) scanf("%lld", &a[i]);
LL ans = -1e19;
REP2(i, 1, n){
REP2(j, i, n){
LL cur_v = 1;
REP2(k, i, j){
cur_v = cur_v * a[k];
}
if(cur_v > ans) ans = cur_v;
}
}
if(ans < 0) ans = 0;
printf("Case #%d: The maximum product is %lld.\n\n", ++ks, ans);
}
return 0;
}