zoukankan      html  css  js  c++  java
  • 九度OJ 1077 最大序列和 -- 动态规划

    题目地址:http://ac.jobdu.com/problem.php?pid=1077

    题目描述:

    给出一个整数序列S,其中有N个数,定义其中一个非空连续子序列T中所有数的和为T的“序列和”。
    对于S的所有非空连续子序列T,求最大的序列和。
    变量条件:N为正整数,N≤1000000,结果序列和在范围(-2^63,2^63-1)以内。
     

    输入:

    第一行为一个正整数N,第二行为N个整数,表示序列中的数。

    输出:

    输入可能包括多组数据,对于每一组输入数据,
    仅输出一个数,表示最大序列和。

    样例输入:
    5
    1 5 -3 2 4
    
    6
    1 -2 3 4 -10 6
    
    4
    -3 -1 -2 -5
    样例输出:
    9
    7
    -1
    /*
     * Main.c
     *
     *  Created on: 2014年1月26日
     *      Author: Shaobo
     */
    #include <stdio.h>
    #include <limits.h>
     
    int main(void){
        long long input;
        int N, i;
        long long max, tmp;
     
        while (scanf ("%d", &N) != EOF){
            max = LLONG_MIN;
            tmp = 0;
            for (i=0; i<N; ++i){
                scanf ("%lld", &input);
                if (tmp > 0)
                    tmp = tmp + input;
                else
                    tmp = input;
                if (tmp > max)
                    max = tmp;
            }
            printf ("%lld
    ", max);
        }
     
        return 0;
    }
    


  • 相关阅读:
    @bzoj
    @bzoj
    @codeforces
    @codeforces
    @bzoj
    @codeforces
    @codeforces
    @codeforces
    @NOIP2018
    反转字符串--C和Python
  • 原文地址:https://www.cnblogs.com/liushaobo/p/4373852.html
Copyright © 2011-2022 走看看