UVA OJ-11095 Maximum Product(暴力求解法)

來源:互聯網
上載者:User

標籤:

 

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
32 4 -352 5 -1 2 -1
Sample Output
Case #1: The maximum product is 8.Case #2: The maximum product is 20.
題目大意:最大連續子序列乘積
#include<iostream>using namespace std;int main() {  int n, a[20], count = 1;  while (cin >> n) {    for (int i = 0; i < n; i++)      cin >> a[i];    long long max = 0;//如果最大乘積不是正數,輸出0     for (int i = 0; i < n; i++) {//枚舉起點       long long sum = 1;      for (int j = i; j < n; j++) {//枚舉終點         sum *= a[j];        if (sum > max)          max = sum;      }     }      cout << "Case #" << count++ << ": The maximum product is " << max << "." << endl;    cout << endl;  }} 

  

UVA OJ-11095 Maximum Product(暴力求解法)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.