Given a sequence of integers S = {S1,S2,...,Sn}, you should determine what is the value of the maximum positive product involving consecutive terms of S. 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 element Si is an integer such that −10 ≤ Si ≤ 10. Next line will have N 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.’, where M is the number of the test case, starting from 1, and P 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 <iostream>
#include <cstdio>
using namespace std;
int main()
{
int n;
int kase=1;
while(scanf("%d",&n)==1&&n)
{
int a[20];
for(int i=0;i<n;i++)
scanf("%d",a+i);
long long sum=1;
long long m=0;
for(int i=0;i<n;i++)
{
for(int j=i;j<n;j++)
{
sum=1;
for(int k=i;k<=j;k++)
sum=a[k]*sum;
m=max(m,sum);
}
}
printf("Case #%d: The maximum product is %lld.\n\n",kase++,m);
}
return 0;
}

Program B 暴力求解的更多相关文章

  1. Program C 暴力求解

    Description   A ring is composed of n (even number) circles as shown in diagram. Put natural numbers ...

  2. Program A - 暴力求解

    Description   Write a program that finds and displays all pairs of 5-digit numbers that between them ...

  3. Program L 暴力求解

    Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...

  4. POJ 1562(L - 暴力求解、DFS)

    油田问题(L - 暴力求解.DFS) Description The GeoSurvComp geologic survey company is responsible for detecting ...

  5. 逆向暴力求解 538.D Weird Chess

    11.12.2018 逆向暴力求解 538.D Weird Chess New Point: 没有读好题 越界的情况无法判断,所以输出任何一种就可以 所以他给你的样例输出完全是误导 输出还搞错了~ 输 ...

  6. 隐型马尔科夫模型(HMM)向前算法实例讲解(暴力求解+代码实现)---盒子模型

    先来解释一下HMM的向前算法: 前向后向算法是前向算法和后向算法的统称,这两个算法都可以用来求HMM观测序列的概率.我们先来看看前向算法是如何求解这个问题的. 前向算法本质上属于动态规划的算法,也就是 ...

  7. BestCoder Round #79 (div.2)-jrMz and angles,,暴力求解~

    jrMz and angle       Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536/65536 K (Java/Other ...

  8. hdu6570Wave (暴力求解)

    Problem Description Avin is studying series. A series is called "wave" if the following co ...

  9. <字符串匹配>KMP算法为何比暴力求解的时间复杂度更低?

    str表示文本串,m表示模式串; str[i+j] 和 m[j] 是正在进行匹配的字符; KMP的时间复杂度是O(m+n)  ,  暴力求解的时间复杂度是O(m*n) KMP利用了B[0:j]和A[i ...

随机推荐

  1. 怎么进入BAT的研发部门?

    怎么进入BAT的研发部门? ======================================剑指offer+leetcode+geeksforgeeks+编程之美+算法导论====秒杀BA ...

  2. latex输入希腊字母

    \alpha产生字符α;\beta产生字符β:\gamma产生字符γ:\delta产生字符δ;\epsilon产生字符ε; \zeta产生字符ζ:\eta产生字符η;\theta产生字符9; \iot ...

  3. python操作mongodb之基础操作

    #coding:utf-8 __author__ = 'hdfs' import pymongo from pymongo import MongoClient client = MongoClien ...

  4. JSON 语法规则详解

    JSON 的语法规则十分简单,无论用何种方法总结都只有数条而已,它参考了 C 语言家族的一些习惯,学习起来并不会感到陌生. 回顾JSON 的五点语法 1)- 数组(Array)用方括号("[ ...

  5. phalcon: (非官方)简单的多模块

    phalcon: [非官方]多模块 配合router使用 例如:我的模块叫做: home 入口文件增加引入: use Phalcon\Mvc\Router; 在自动引入前面增加,自动引入命名空间: / ...

  6. 串行通讯之.NET SerialPort

    第1章串行通讯之.NET SerialPort    2 1 枚举串口    2 2 打开/关闭串口    2 3 写数据    3 3.1 写二进制数据    3 3.2 写文本数据    4 4 ...

  7. Google V8扩展利器发布:v8-native-binding-generator

    用C++扩展Google V8很简单,但是类比较多时还是很烦的.前段时间开发cantk-runtime-v8时,我写了一个代码产生器v8-native-binding-generator,让扩展Goo ...

  8. WLAN历史概述-01

    无线网络介绍 无线网络的初步应用,可以追朔到第二次世界大战期间,当时美国陆军采用无线电信号做资料的传输.他们研发出了一套无线电传输科技,并且采用相当高强度的加密技术,得到美军和盟军的广泛使用.他们也许 ...

  9. 为MySQL选择合适的备份方式

    数据库的备份是极其重要的事情.如果没有备份,遇到下列情况就会抓狂: UPDATE or DELETE whitout where… table was DROPPed accidentally… IN ...

  10. 找不到 -lz解决方法

    sudo apt-get install libghc-zlib-dev