zoukankan      html  css  js  c++  java
  • codevs 2622 数字序列

    2622 数字序列

     提交地址:http://codevs.cn/problem/2622/

     时间限制: 1 s
     空间限制: 32000 KB
     题目等级 : 黄金 Gold
     
     
    题目描述 Description

    给定一个长度为n的一个序列A1,A2,…,An,求序列中连续子序列的最大和。

    例如:当输入为-5,3,5,7,-15,6,9,27,-36,10时,连续子序列6,9,27的和为42是最大值;而当序列变成-5,3,5,8,-15,6,9,27,-36,10时,连续子序列3,5,8,-15,6,9,27的和为43是最大值。

    输入描述 Input Description

    第一行为n (n≤1000),第二行为n个数,表示序列Ai(-10000≤Ai≤10000)。

    输出描述 Output Description

    一个数,表示连续子序列的最大和。

    样例输入 Sample Input

    10

    -5 3 5 8 -15 6 9 27 -36 10

    样例输出 Sample Output

    43

     1 #include<cstdio>
     2 
     3 int n;
     4 
     5 int a[1000+10];
     6 int b[1000+10];
     7 int ans=-1000000;
     8 
     9 int main()
    10   {
    11       scanf("%d",&n);
    12       for(int i=1;i<=n;i++)
    13         scanf("%d",&a[i]);
    14       for(int i=1;i<=n;i++)
    15         for(int j=i+1;j<=n;j++)
    16           {
    17               int p=0;
    18               for(int k=i;k<=j;k++)
    19                 p+=a[k];
    20               if(p>ans) ans=p;
    21           }    
    22       printf("%d",ans);
    23       return 0;
    24   }

    -10000≤Ai≤10000

    n≤1000

  • 相关阅读:
    音视频之音频(三)
    音视频之声音(二)
    音视频之图片(一)
    页面错位问题
    苹果账号恢复
    js使用逗号拼接id并去重
    Nginx常用命令
    java拼接字符串、格式化字符串方式
    Ajax 请求
    raw.githubusercontent.com port 443: Connection refused
  • 原文地址:https://www.cnblogs.com/yuemo/p/5540131.html
Copyright © 2011-2022 走看看