您的位置:首页 > 编程语言 > C语言/C++

例题7-2 最大乘积(Maximum Product, UVa 11059)

2017-09-26 22:15 411 查看
通过枚举左右区间来枚举连续子序列。。这数据,随便瞎搞。。。还是迷之wa了几发。。QAQ。。
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <utility>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cctype>
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define IN() freopen("in.txt", "r", stdin)
#define OUT() freopen("out.txt", "w", stdout)
#define LL long long
#define maxn 105
#define maxm 10005
#define mod 1000000007
#define INF 1000000007
#define eps 1e-5
#define PI 3.1415926535898
#define N 26
using namespace std;
//-------------------------CHC------------------------------//
LL a[20];

int main() {
int n, kase = 1;
while (~scanf("%d", &n)) {
for (int i = 0; i < n; ++i) {
scanf("%lld", &a[i]);
}
LL ans = 0;
for (int l = 0; l < n; ++l)
for (int r = l + 1; r <= n; ++r) {
LL prod = 1;
for (int i = l; i < r; ++i)
prod *= a[i];
ans = max(ans, prod);
}
if (kase > 1) putchar('\n');
printf("Case #%d: The maximum product is %lld.\n", kase++, ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息