题目1077:最大序列和(最大连续子序列和)
题目链接:http://ac.jobdu.com/problem.php?pid=1077
详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus
参考代码:
// // 1077 最大序列和.cpp // Jobdu // // Created by PengFei_Zheng on 03/05/2017. // Copyright © 2017 PengFei_Zheng. All rights reserved. // #include <stdio.h> #include <iostream> #include <algorithm> #include <string.h> #include <cstring> #include <cmath> #include <climits> #define MAX_SIZE 1000001 //#define debug using namespace std; int n; long long a[MAX_SIZE]; int main(){ #ifdef debug freopen("/Users/pengfei_zheng/Desktop/input.txt", "r", stdin); #endif while(scanf("%d",&n)!=EOF){ memset(a,0,sizeof(a)); long long sum = LONG_LONG_MIN; long long tmp = LONG_LONG_MIN; for(int i = 0 ; i < n ; i ++){ scanf("%lld",&a[i]); if(tmp>0) tmp+=a[i]; else tmp = a[i]; if(tmp>sum) sum=tmp; } printf("%lld\n",sum); } return 0; } /************************************************************** Problem: 1077 User: zpfbuaa Language: C++ Result: Accepted Time:250 ms Memory:9332 kb ****************************************************************/
作者: 伊甸一点
出处: http://www.cnblogs.com/zpfbuaa/
本文版权归作者伊甸一点所有,欢迎转载和商用(须保留此段声明),且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
原文链接 如有问题, 可邮件(zpflyfe@163.com)咨询.