Program B 暴力求解
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 暴力求解的更多相关文章
- Program C 暴力求解
Description A ring is composed of n (even number) circles as shown in diagram. Put natural numbers ...
- Program A - 暴力求解
Description Write a program that finds and displays all pairs of 5-digit numbers that between them ...
- Program L 暴力求解
Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...
- POJ 1562(L - 暴力求解、DFS)
油田问题(L - 暴力求解.DFS) Description The GeoSurvComp geologic survey company is responsible for detecting ...
- 逆向暴力求解 538.D Weird Chess
11.12.2018 逆向暴力求解 538.D Weird Chess New Point: 没有读好题 越界的情况无法判断,所以输出任何一种就可以 所以他给你的样例输出完全是误导 输出还搞错了~ 输 ...
- 隐型马尔科夫模型(HMM)向前算法实例讲解(暴力求解+代码实现)---盒子模型
先来解释一下HMM的向前算法: 前向后向算法是前向算法和后向算法的统称,这两个算法都可以用来求HMM观测序列的概率.我们先来看看前向算法是如何求解这个问题的. 前向算法本质上属于动态规划的算法,也就是 ...
- 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 ...
- hdu6570Wave (暴力求解)
Problem Description Avin is studying series. A series is called "wave" if the following co ...
- <字符串匹配>KMP算法为何比暴力求解的时间复杂度更低?
str表示文本串,m表示模式串; str[i+j] 和 m[j] 是正在进行匹配的字符; KMP的时间复杂度是O(m+n) , 暴力求解的时间复杂度是O(m*n) KMP利用了B[0:j]和A[i ...
随机推荐
- Android入门:绑定本地服务
一.绑定服务介绍 前面文章中讲过一般的通过startService开启的服务,当访问者关闭时,服务仍然存在: 但是如果存在这样一种情况:访问者需要与服务进行通信,则我们需要将访问者与服务进行绑定: ...
- commonJS — 对象操作(for Object)
for Object github: https://github.com/laixiangran/commonJS/blob/master/src/forObject.js 代码 /** * Cre ...
- 自定义ExpressionBuilder
ExpressionBuilder的常见说明见https://msdn.microsoft.com/zh-cn/library/System.Web.Compilation.ExpressionBui ...
- virutalbox虚拟机硬盘扩容
大小改变为30GB VBoxManage modifyhd d:\newxp.vdi --resize 30000 然后用diskgenius扩从容量
- 为学Linux 我看了这些书
去年开始,抱着学习的态度开始了我的Linux学习,到现在,差不多一年了,收获很多,不敢说精通Linux,但是,还是对得起“略懂”这两个字的.这一年里我看了很多书,细细数下,大概15本左右,其中包含了两 ...
- BliBli抢楼全攻略
B站抢楼是一个很好玩的事情,每当新番出新集时.总有很多人想能够在前排发表评论,但是因为人数众多,往往不能如愿,今天就教大家一个抢楼的好办法. 我们平时抢楼的整个流程是这样的: 1.在官方放出的新番更新 ...
- C# System.Diagnostics.Stopwatch 类
测量一个时间间隔的运行时间 a.调用 Start 方法 b.调用 Stop 方法 c.使用 Elapsed 属性检查运行时间. 如: System.Diagnostics.Stopwatch stop ...
- eclipse 下面的folder,source folder,package的区别与作用
首先明确一点,folder,source folder,package都是文件夹,既然是文件夹,那么任何的文件都可以往这三种文件夹下面的放.1.他们的区别folder就是普通的文件夹,它和我们wind ...
- Web前端开发面试题
1. 以下的代码有问题吗?如果有你觉着应该如何修改? for(int i=0; i<list.size(); i++) { ..... ..... if(...) { list.re ...
- hdu----(1847)Good Luck in CET-4 Everybody!(简单巴什博奕)
Good Luck in CET-4 Everybody! Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...