题目描述
思路
两重循环就可以了,但要注意吧答案定义为long long(因为 1 <= n <= 18, -10 <= Si <= 10。
具体代码
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <unordered_map>
#include <map>
#include <set>
using namespace std;
#define mcpy(b, a) memcpy(b, a, sizeof a)
#define mset(a) memset(a, 0, sizeof a)
#define pb push_back
#define fi first
#define se second
#define mp make_pair
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 1e9;
int a[20];
int main() {
int n;
int t = 0;
while (scanf("%d", &n) == 1) {
t ++;
for (int i = 0; i < n; i ++ )
scanf("%d", &a[i]);
LL max = 0;
for (int i = 0; i < n; i ++ ) {
LL ans = 1;
for (int j = i; j < n; j ++ ) {
ans *= (LL)a[j];
if (ans > max) max = ans;
}
}
printf("Case #%d: The maximum product is %lld.\n\n", t, max);
}
return 0;
}