题意:给出n个数组成的序列,求乘积最大的连续子序列

看的紫书,因为n最大为18,每个数最大为10,所以10^18用long long 能够存下, 直接枚举起点和终点找最大值就可以了

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include <cmath>
 5 #include<stack>
 6 #include<vector>
 7 #include<map>
 8 #include<queue>
 9 #include<algorithm>
10 #define mod=1e9+7;
11 using namespace std;
12
13 typedef long long LL;
14 int a[105];
15
16 int main(){
17     LL ans,maxn;
18     int i,j,n,cas=1;
19     while(scanf("%d",&n)!=EOF){
20         for(i=1;i<=n;i++) scanf("%d",&a[i]);
21         maxn=-1000;
22
23         for(i=1;i<=n;i++){
24             ans=a[i];
25             maxn=max(ans,maxn);
26             for(j=i+1;j<=n;j++){
27                 ans*=a[j];
28                 maxn=max(ans,maxn);
29             //    printf("ans=%d\n",ans);
30
31             }
32         }
33         if(maxn<0) maxn=0;
34         printf("Case #%d: The maximum product is %lld.\n\n",cas++,maxn);
35     }
36     return 0;
37 }

View Code

转载于:https://www.cnblogs.com/wuyuewoniu/p/4346025.html

UVa 11059 Maximum Product相关推荐

  1. UVa 11059 - Maximum Product

    题目:最大字段积. 分析:dp,最大字段和类似物.求解过程同最大字段和. 这里注意,设置两个状态:以本元素结束时,最大正值和最小的负值. 更新时.假设data[i]为正,则相应跟新,假设data[i] ...

  2. UVA - 11059 Maximum Product-暴力枚举

    输入n个元素组成的序列s,找出一个乘积最大的连续子序列,如果这个子序列不是整数,则输出0. 解题思路: 枚举起点和终点,把中间的数相乘,然后找到最大的结果. 代码如下: #include <io ...

  3. 暴力求解——最大乘积 Maximum Product,UVa 11059

    最大乘积 Maximum Product 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=84562#problem/B 解题思路 ...

  4. 【例题 7-2 UVA - 11059】Maximum Product

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] C语言for循环练习题 [代码] /*1.Shoud it use long long ?2.Have you ever test ...

  5. UVA11059 Maximum Product

    问题链接:UVA11059 Maximum Product.基础级练习题,用C语言编写程序. 题意简述:输入n个整数序列,有正有负,求这个序列中最大连续累乘的子序列,其最大的值为多少.如果结果为负数, ...

  6. LeetCode 152. Maximum Product Subarray--动态规划--C++,Python解法

    题目地址:Maximum Product Subarray - LeetCode Given an integer array nums, find the contiguous subarray w ...

  7. Maximum Product of Word Lengths

    Maximum Product of Word Lengths 题目链接: https://leetcode.com/problems... public class Solution {public ...

  8. 【LeetCode】152. Maximum Product Subarray

    题目: Find the contiguous subarray within an array (containing at least one number) which has the larg ...

  9. LeetCode 628. Maximum Product of Three Numbers

    题目: Given an integer array, find three numbers whose product is maximum and output the maximum produ ...

最新文章

  1. 函数的四种调用模式.上下文调用.call.apply
  2. 百度网盘迎来劲敌!非会员下载速度10MB/S……
  3. java避免空指针异常_避免Java中的空指针异常
  4. AI算法连载20:统计之隐马尔可夫模型
  5. 从零开始学前端:标签渐变和媒体查询 --- 今天你学习了吗?(CSS:Day25)
  6. windows环境下部署Tomcat到服务器
  7. linux权限设定的判定,linux中如何通过脚本判定文件的群组权限
  8. 1小时学会jenkins集成邮件/微信/钉钉通知
  9. Apache CXF实战之二 集成Sping与Web容器
  10. 使用 telnet 命令 查看端口的开放、可用情况
  11. mac memcached_如何在Mac OS上安装Memcached Server
  12. Spring Boot实现动态数据库配置
  13. python 和 的区别_Python中is和==的区别
  14. python生成序列_python如何生成随机序列?
  15. Unity 序列帧动画
  16. 高德地图聚合自定义样式
  17. 0x00007FF73361E515 处(位于 基于多态的职工管理系统.exe 中)引发的异常: 0xC0000005: 职工岗位输入不是1,2,3,而是其他乱七八糟的
  18. 对于刺头,怎么办?9个套路支招
  19. chloe.mysql 源码_AceFx-基于Nfine的Chloe官网及后台源码
  20. Segmentation笔记4-Boundary-Aware Network for Fast and High-Accuracy Portrait Segmentation

热门文章

  1. ibatis 中 $与#的区别
  2. asp.net控件开发基础(2)
  3. elk docker
  4. 咕泡-模板方法 template method 设计模式笔记
  5. 【284天】我爱刷题系列(43)
  6. Codeforces 835 F Roads in the Kingdom(树形dp)
  7. 网络工程师第五站-有线、无线同网段混合组网(多FAT案例)
  8. Javascrip之匿名函数
  9. Hello Views之Spinner(yaozq翻译,仅供参考)
  10. opencv 在debian6.0下安装