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. android坐标

    说来说去都不如 画图示意 简单易懂啊!!!真是的! 来吧~~先上张图~~! (一)首先明确一下 android 中的坐标系统 :      屏幕的左上角是坐标系统原点(0,0)      原点向右延伸 ...

  2. virtualbox中centos系统配置nat+host only上网(zhuan)

    http://www.cnblogs.com/leezhxing/p/4482659.html **************************************************** ...

  3. 搭建一个简单的Struts2框架

    1  创建一个web项目. 2 导入必要的JAR文件. 放在WEB-INF下lib包里. 3 添加web.xml配置,添加启动配置. <?xml version="1.0" ...

  4. android 存储

    总共四种:SharedPreferences,文件存储,SQLite数据库,ContentProvider,网络存储 1.sharedPreferences:适合存储少量数据,而且存取的格式简单,采用 ...

  5. [转]使用git命令上传代码

    http://jiajing.elastos.org/2013/04/15/%E4%BD%BF%E7%94%A8git%E5%91%BD%E4%BB%A4%E4%B8%8A%E4%BC%A0%E4%B ...

  6. Unity3D Mecanim 动画系统骨骼动画问题解决方法

    http://7dot9.com/2014/08/16/unity3d-mecanim%E5%8A%A8%E7%94%BB%E7%B3%BB%E7%BB%9F%E9%AA%A8%E9%AA%BC%E5 ...

  7. rand()和srand()GetTickCount函数用法

    标准库<cstdlib>(被包含于<iostream>中)提供两个帮助生成伪随机数的函数: 函数一:int rand(void):从srand (seed)中指定的seed开始 ...

  8. canvas实现钟表

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. 5.6 WebDriver API实例讲解(16-30)

    16.操作单选框 被测试的网页为Demo1. Java语言版本的API实例代码: public static void operateRadio(){ driver.get("file:// ...

  10. sql server多表数据批量更新

    update wset w.TagCount=x.TagCountfrom (select ItemID,COUNT(*) as TagCount from r where IsValid=1 gro ...