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

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 aftereach test case. The input is terminated by end of file (EOF).

For each test case you must print the message: Case #M: The maximum product is P., where M isthe number of the test case, starting from 1, and P is the value of the maximum product. Aftereach test case you must print a blank line.

3
2 4 -3 5
2 5 -1 2 -1
Case #1: The maximum product is 8.

Case #2: The maximum product is 20.

枚举每一个长度组合,不断更新最大值,不过要注意有可能18个数都是10,那么最大值是多少?int还存得下吗?
#include"iostream"
#include"cstring"
using namespace std;
int main()
{
long long ans=-;
int ch,f;
long long an=;
int a[];
f=;
int n;
while(cin>>n)
{
for(int i=;i<n;i++)
{
cin>>ch;
a[i]=ch;
an*=ch;
if(an>ans)
{
ans=an;
}
}
for(int j=n-;j>=;j--)
{
an=;
for(int k=j;k>=;k--)
{
an*=a[k];
if(an>ans)
{
ans=an;
}
}
}
if(ans<) ans=;
cout<<"Case #"<<f++<<": The maximum product is "<<ans<<'.'<<endl;
cout<<endl;
ans=-;
an=;
} return ;
}
												

Maximun product的更多相关文章

  1. 最大乘积 Maximun Product

    最大乘积 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84562#problem/B 题意: 输入n个元素组成的序列s,你需要 ...

  2. leecode 每日解题思路 152 Maximun Product Subarray

    问题描述: 问题链接:152 Maximum Product Subarray 在经典的算法解析中, 有关的分治和动态规划的,经典题型之一就是求最大子段和, 这道题就是他的变形:求最大子段积; 这个问 ...

  3. 枚举专项练习_Uva725(Division)_Uva11059(Maximun Product)

    //Uva725 #include <iostream> #include <cstring> #include <cstdlib> #include <cs ...

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

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK

  5. [LeetCode] Product of Array Except Self 除本身之外的数组之积

    Given an array of n integers where n > 1, nums, return an array output such that output[i] is equ ...

  6. [LeetCode] Maximum Product Subarray 求最大子数组乘积

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  7. vector - vector product

    the inner product Givens two vectors \(x,y\in \mathbb{R}^n\), the quantity \(x^\top y\), sometimes c ...

  8. 1 Maximum Product Subarray_Leetcode

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  9. Leetcode Maximum Product Subarray

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

随机推荐

  1. ibatais.net 连接 mysql 最全配置写法

    1.安装环境: 1.       vs2013 (vs开发工具) 2.       mysql 5.7.10.0 (安装的mysql 数据库版本) https://dev.mysql.com/doc/ ...

  2. NOI题库--盒子和小球系列 By cellur925

    题目传送门 盒子和小球之二:N个有差别的盒子(1<=N<=20).你有A个红球和B个蓝球.0 <= A <= 15, 0 <= B <= 15.球除了颜色没有任何区 ...

  3. 利用OneDNS同步chrome数据

    将DNS服务器改成OneDNS的 117.50.11.11 备用改为 117.50.22.22 然后刷新自己的DNS缓存,接着测试一下https://test.onedns.net即可 这样既可以正常 ...

  4. 转载:4412环境搭建:arm-linux-gcc: 没有那个文件或目录

    4412环境搭建:arm-linux-gcc: 没有那个文件或目录 2014年10月15日 ⁄ 环境搭建 ⁄ 共 993字 ⁄ 字号 小 中 大 ⁄ 评论 11 条 ⁄ 阅读 6,125 次 最近弄了 ...

  5. 转】SparkSQL中的内置函数

    原博文来自于: http://blog.csdn.net/u012297062/article/details/52207934    感谢! 使用Spark SQL中的内置函数对数据进行分析,Spa ...

  6. angular.module 参数的意思

    定义一个module需要两个参数,第一个作为module的名字,第二个则是指出这个module都依赖哪些别的modules

  7. Android开发学习——android反编译

    第一种: 1.下载下边的三个jar包,对dex2jar和jd-gui进行解压 2.将需要反编译的apk后缀名改为.rar,然后进行解压 3.将解压后生成的classes.dex加入第一步解压后的dex ...

  8. Java 208道面试题及部分答案

    ---恢复内容开始--- 一.Java 基础 1.JDK 和 JRE 有什么区别? 答:JRE是java运行时环境,包含了java虚拟机,java基础类库.是使用java语言编写的程序运行所需要的软件 ...

  9. FastDFS的简单使用

    互联网中有海量的文件,比如电商网站有海量的图片文件,视频网站有海量的视频文件,如果使用传统的模式上传文件,肯定是不可取的.因此需要使用第三方服务器来存储图片 . 一.FastDFS简介 ​ FastD ...

  10. ie浏览器和火狐浏览器对对容器宽度定义的差异

    首先我们说说firefox和IE对CSS的宽度显示有什么不同: 其实CSS ’width’ 指的是标准CSS中所指的width的宽度,在firefox中的宽度就是这个宽度.它只包含容器中内容的宽度.而 ...