您的位置:首页 > 其它

UVa--11059 Maxumum Produce(枚举)

2016-02-06 14:39 267 查看
传送门

题意:

找出序列S的乘积最大的连续子序列,如果最大的乘积不是正数,输出0. 1 <= n <= 18, -10 <= Si <= 10.

题解:

数据规模小,直接枚举各个子序列,取其最大乘积。

注:UVa OJ的c++11编译器不支持%I64d输出,提交n多次才醒悟,泪。。

# include <iostream>
# include <cstdio>
# include <algorithm>
using namespace std;

const int maxn = 20;
int s[maxn];

int main()
{
int cases = 1, n;

while(cin >> n)
{
for(int i = 0; i < n; ++i)
cin >> s[i];
long long ans = 0;
long long tmp = 1;
for(int i = 0; i < n; ++i)
{
tmp = s[i];
ans = max(ans, tmp);
for(int j = i + 1; j < n; ++j){
tmp *= s[j];
ans = max(ans, tmp);
}
}
printf("Case #%d: The maximum product is %lld.\n\n", cases++, ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  UVa 枚举 easy