Problem D - Maximum Product

Time Limit: 1 second

Given a sequence of integers S = {S1, S2, ..., Sn}, you should determine what is the value of the maximum positive product involving consecutive terms ofS. If you cannot find a positive sequence, you should consider 0 as the value of the maximum product.

Input

Each test case starts with 1 ≤ N ≤ 18, the number of elements in a sequence. Each elementSi is an integer such that-10 ≤ Si ≤ 10. Next line will haveN integers, representing the value of each element in the sequence. There is a blank line after each test case. The input is terminated by end of file (EOF).

Output

For each test case you must print the message: Case #M: The maximum product is P., whereM is the number of the test case, starting from1, andP is the value of the maximum product. After each test case you must print a blank line.

Sample Input

3
2 4 -3 5
2 5 -1 2 -1

Sample Output

Case #1: The maximum product is 8.

Case #2: The maximum product is 20.
#include <stdio.h>
#include <set> using namespace std; int main(){
int n;
int * val = NULL;
set<long long> s;
while((scanf("%d",&n) == 1) && n != 0){
val = new int[n];
int i = 0;
for (;i < n; i++) {
scanf("%d",&val[i]);
}
s.clear();
int j ;
for(i = 0;i < n -1;i++){ //枚举起点 for (j = i; j < n; ++j) {//枚举终点
int k;long long ji = 1;
for(k = i; k <= j;k++){
ji *= val[k];
}
s.insert(ji);
} } long long max = *(s.rbegin());
if(max > 0){
printf("%ld\n",max);
}
else{
printf("0\n");
}
                delete val;
        } return 0; }

最大乘积(Maximum Product,UVA 11059)的更多相关文章

  1. 暴力求解——最大乘积 Maximum Product,UVa 11059

    最大乘积 Maximum Product 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84562#problem/B 解题思路 ...

  2. Maximum Product UVA - 11059

    Given a sequence of integers S = {S1, S2, . . . , Sn}, you should determine what is the value of the ...

  3. [Swift]LeetCode628. 三个数的最大乘积 | Maximum Product of Three Numbers

    Given an integer array, find three numbers whose product is maximum and output the maximum product. ...

  4. [Swift]LeetCode318. 最大单词长度乘积 | Maximum Product of Word Lengths

    Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the tw ...

  5. 【LeetCode】1464. 数组中两元素的最大乘积 Maximum Product of Two Elements in an Array (Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 暴力 找最大次大 日期 题目地址:https://le ...

  6. UVa 11059 - Maximum Product 最大乘积【暴力】

    题目链接:https://vjudge.net/contest/210334#problem/B 题目大意:Given a sequence of integers S = {S1, S2, . . ...

  7. UVA 11059 Maximum Product【三层暴力枚举起终点】

    [题意]:乘积最大的子序列.n∈[1,10],s∈[-10,10] [代码]: #include<bits/stdc++.h> using namespace std; int a[105 ...

  8. uva 11059 maximum product(水题)——yhx

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK

  9. Uva 11059 Maximum Product

    注意long long  long long  longlong !!!!!!   还有 printf的时候 明明longlong型的答案 用了%d  WA了也看不出,这个细节要注意!!! #incl ...

随机推荐

  1. 解放程序猿宝贵的右手(或者是左手) ——Android自动化测试技巧

    解放双手--Android自动化测试 - eclipse_xu - 博客频道 - CSDN.NET 解放程序猿宝贵的右手(或者是左手) --Android自动化测试技巧

  2. 提高效率 常用的几个xcode快捷键

    能用好快捷键,不仅仅可以提高工作效率,而且让你看起来更加的自信和能干,下面几个常用的快捷键,希望对你在工作中有帮助 1.首先说明一下几个标示的意思 Command  ⌘ Control      ⌃ ...

  3. eclipse的svn插件安装方式

    eclipse的插件安装一般有3种方式: 1)通过eclipse的Help/ Install New Software...中, 点击Add, 添加一个在线更新地址,如:http://subclips ...

  4. c#基础语言编程-正则表达式应用

    引言 在不同语言中虽正则表达式一样,但应用函数还是有所区别,在c#语言中使用Regex. 可以通过以下两种方式之一使用正则表达式引擎: 通过调用 Regex 类的静态方法. 方法参数包含输入字符串和正 ...

  5. [置顶] UITableViewCell

    UITableViewCellStyle: 四种Cell类型. UITableViewCellSeparatorStyle 分割线类型.(group三种,plain两种) UITableViewCel ...

  6. winform 曲线(贝塞尔) 分类: WinForm 2014-12-29 16:52 109人阅读 评论(0) 收藏

    <span style="font-size:14px;">//覆盖OnPaint事件</span> <span style="font-s ...

  7. 几个 PHP 的“魔术常量”

    PHP 向它运行的任何脚本提供了大量的预定义常量.不过很多常量都是由不同的扩展库定义的,只有在加载了这些扩展库时才会出现,或者动态加载后,或者在编译时已经包括进去了. 有八个魔术常量它们的值随着它们在 ...

  8. android edittext 点击回车会响应两次的解决方案

    由于Key有Down和Up事件,所以会执行两次. class editTextOnKeyClickListener implements etOnKeyClickListener { @Overrid ...

  9. mysql内核源代码深度解析 缓冲池 buffer pool 整体概述

    http://blog.csdn.net/cjcl99/article/details/51063078

  10. Qt 学习之路:输入元素

    前面的章节中,我们看到了作为输入元素的MouseArea,用于接收鼠标的输入.下面,我们再来介绍关于键盘输入的两个元素:TextInput和TextEdit. TextInput是单行的文本输入框,支 ...