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 ;
}
												

最新文章

  1. 如何在 Evernote 中支持代码高亮
  2. unicode编码与utf-8 区别
  3. 2016HUAS_ACM暑假集训4C - 递推
  4. 代码生成工具Database2Sharp中增加视图的代码生成以及主从表界面生成功能
  5. 图文转换——NABCD
  6. iOS开发拓展篇—音频处理(音乐播放器5)
  7. VirtIE6
  8. java命令行参数
  9. Objective-c初始化和便利构造
  10. baidu面试题
  11. 3D MAX脚本教程1
  12. 用Maven创建web项目
  13. Jenkins中的一些问题解决(~~不断更新~~)
  14. 《设计模式之禅》--MVC框架
  15. [POI2014]KUR-Couriers
  16. C# for Python(Nugut Iron包)
  17. 国内写的比较好的markdown教程
  18. myeclipse maven的联系
  19. 2d游戏和 3d游戏的区别
  20. ubuntu14.04 解析不了域名—ubuntu的DNS配置

热门文章

  1. JavaScript--DOM浏览器窗口可视区域大小
  2. 暑期训练狂刷系列——Hdu 1698 Just a Hook (线段树区间更新)
  3. hihoOffer收割练习20题目2
  4. 贪心+枚举/哈希表 HDOJ Trouble
  5. 题解报告:poj 2299 Ultra-QuickSort(BIT求逆序数)
  6. 光盘安装ubuntu出现busybox-initramfs不能继续安装的终极解决方法
  7. 单例模式及php实现
  8. WIN7 x64下java 8的环境变量配置
  9. git ---合并和删除分支
  10. 最实用解决tomcat startup.bat 一闪而过