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. 我的spring cloud项目历程(2018.3~2018.9)

    前言 今天是9月17日,趁着山竹的临幸,得以在家里舒适的办公.项目从3月底开始,至今刚好半年.抽几十分钟,总结下半年的历程.对后面的项目,应该也有一点帮助吧. 学习前的七个问题 项目开始前,由于某些特 ...

  2. linux unzip和zip

    注:*压缩成限.zip格式文件 常用解压缩: [root@mysql test]# unzip -o test.zip -d tmp/ 将压缩文件test.zip在指定目录tmp下解压缩,如果已有相同 ...

  3. Webform 内置对象 Response对象、Request对象,QueryString

    Request对象:获取请求Request["key"]来获取传递过来的值 QueryString:地址栏数据传递 ?key=value&key=value注意事项:不需要 ...

  4. [BZOJ2005][NOI2010]能量采集 数学

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2005 发现与$(0,0)$连线斜率相同的点会被挡住.也就是对于$(a,b)$且$gcd(a ...

  5. 浅谈网上的zoomlistview存在的问题

    最近项目主要是做一个类似wps文档阅历的功能,以列表的形式显示文档,并且需要实现缩放平移.而网上关于此类功能的实现主要是通过自定义的listview实现的,类名为ZoomListView. 网上的zo ...

  6. Python学习 Day 5 高阶函数 map/reduce filter sorter 返回函数 匿名函数 装饰器 偏函数

    高阶函数Higher-orderfunction 变量可以指向函数 >>> abs #abs(-10)是函数调用,而abs是函数本身 <built-in function ab ...

  7. 【译】x86程序员手册41-10.6 TLB(快表)测试

    译注:本章基本未做翻译 10.6 TLB Testing TLB测试 The 80386 provides a mechanism for testing the Translation Lookas ...

  8. patest_1007_Maximum Subsequence Sum_(dp)(思维)

    1007. Maximum Subsequence Sum (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...

  9. chroot - 以 特定 根 目录 运行 命令 或者 交互式 shell

    总览 (SYNOPSIS) chroot [OPTION] NEWROOT [COMMAND...] chroot OPTION 描述 (DESCRIPTION) 以 NEWROOT 为 根 目录 运 ...

  10. 【leetcode-03】给定一个字符串,请你找出其中不含有重复字符的最长子串的长度

    开个新坑,leetcode上面做题目.下面是题目描述: <!-- 给定一个字符串,请你找出其中不含有重复字符的最长子串的长度. 示例 1: 输入: "abcabcbb" 输出 ...