Maximun product
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的更多相关文章
- 最大乘积 Maximun Product
最大乘积 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84562#problem/B 题意: 输入n个元素组成的序列s,你需要 ...
- leecode 每日解题思路 152 Maximun Product Subarray
问题描述: 问题链接:152 Maximum Product Subarray 在经典的算法解析中, 有关的分治和动态规划的,经典题型之一就是求最大子段和, 这道题就是他的变形:求最大子段积; 这个问 ...
- 枚举专项练习_Uva725(Division)_Uva11059(Maximun Product)
//Uva725 #include <iostream> #include <cstring> #include <cstdlib> #include <cs ...
- uva 11059 maximum product(水题)——yhx
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAB1QAAAMcCAIAAABo0QCJAAAgAElEQVR4nOydW7msuhKF2wIasIAHJK
- [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 ...
- [LeetCode] Maximum Product Subarray 求最大子数组乘积
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- vector - vector product
the inner product Givens two vectors \(x,y\in \mathbb{R}^n\), the quantity \(x^\top y\), sometimes c ...
- 1 Maximum Product Subarray_Leetcode
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- Leetcode Maximum Product Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
随机推荐
- Ubuntu 18.04 LTS 系统设置打不开了
在更换软件源后,安装了vim 和chrome,chrome很顺利,但是安装vim的时候后就显示有问题了,有的依赖版本不对,嫌版本太高,卸载后再装可以. 安装了python和python2 依旧是有些依 ...
- iOS 消除Xcode警告
- undeclared selector #pragma clang diagnostic push #pragma clang diagnostic ignored"-Wundeclar ...
- win7 右键菜单残影 消除方法
1. 治标法: 右键桌面->更改分辨率 随便换一个分辨率再还原就OK了! 2. 根治法: 我的电脑-> 属性 ->高级选项-> 高级-> 设置-> 自定义 不 ...
- Qt之程序发布以及打包成exe安装包
一.简述 Qt项目开发完成之后,需要打包发布程序,而因为用户电脑上没有Qt配置环境,所以需要将release生成的exe文件和所依赖的dll文件复制到一个文件夹中,然后再用 Inno Setup打包工 ...
- 51Nod 1315 合法整数集
1315 合法整数集 题目来源: TopCoder 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题 收藏 关注 一个整数集合S是合法的,指S的任意子集subS有Fu ...
- .NET下集中实现AOP编程的框架
一.Castle 使用这个框架呢,首先是需要安装NuGet包. 先建立一个控制台项目,然后在NuGet中搜索Castle.Windsor,不出意外的话应该能找到如下的包 然后安装,会自动的安装包Cas ...
- Spirng MVC +Velocity 表单绑定命令对象
通常,表单中的数据在提交之后可以通过Spring MVC的@RequestParam注解在控制器函数的参数列表中中提取出来,但是一旦表单数据过多的话,参数列表将会变得非常长,最好的解决方案是将表单中的 ...
- C. Mahmoud and a Message dp + 暴力
http://codeforces.com/contest/766/problem/C 关键在于dp,如何计数. 设dp[i]表示前i个字母中,能分成多少份合法的情况.那么答案就是dp[n],其中dp ...
- D. Chloe and pleasant prizes 树上dp + dfs
http://codeforces.com/contest/743/problem/D 如果我们知道mx[1]表示以1为根节点的子树中,点权值的最大和是多少(可能是整颗树,就是包括了自己).那么,就可 ...
- python vs java的rsa加密
首先:java的加密解密模块需要更加精细的算法细节指定 java的加密方式 javax.crypto.Cipher,定义的获取方式 tatic Cipher getInstance(String tr ...