最大连续数列的和
2017-03-09 16:01
246 查看
最大连续数列的和
Time Limit:1000MS Memory Limit:65536K
Total Submit:142 Accepted:83
Description
求最大连续子序列的和
Input
第一行输入n(n<=500),第二行为n个以空格分开的整数(-1000到1000之间);
Output
该序列中最大的连续子序列的和
Sample Input
Sample Output
21
Time Limit:1000MS Memory Limit:65536K
Total Submit:142 Accepted:83
Description
求最大连续子序列的和
Input
第一行输入n(n<=500),第二行为n个以空格分开的整数(-1000到1000之间);
Output
该序列中最大的连续子序列的和
Sample Input
6 1 2 -5 6 7 8
Sample Output
21
var a,f:array[0..1000] of longint; n,m,j,i,max:longint; begin readln(n); for i:=1 to n do read(a[i]); for i:=1 to n do begin if (a[i]+f[i-1]>0) and (f[i-1]<>0) then f[i]:=a[i]+f[i-1]; if (a[i]+f[i-1]<0) and (f[i-1]<>0) then f[i]:=0; if f[i-1]=0 then if a[i]>0 then f[i]:=a[i] else f[i]:=0; end; for i:=1 to n do if f[i]>max then max:=f[i]; write(max); end.
相关文章推荐
- 求最大连续子数列和(只扫描一次数列)
- 最大连续数列和
- 最大连续数列的和
- 最大连续数列的和
- Maximum Subsequence Sum最大连续数列和
- 求最大连续子数列和(只扫描一次数列)
- 《Cracking the Coding Interview程序员面试金典》----最大连续数列和
- 最大连续字数列和的问题
- 最大连续数列的和-SSL 1461
- 在一个数列中找出最大和的连续子列
- 求最大连续子数列和(只扫描一次数列)
- SSL 1461——最大连续数列的和
- KT学算法(一)——数列连续子列最大和问题的O(n)解法
- hdu 3415 Max Sum of Max-K-sub-sequence 单调队列 求连续l(1<=l<=k)个数的和的最大值 数列可循环
- 最大连续数列的和
- (ssl1461)最大连续数列的和
- 最大连续数列的和
- 不连续数列的最大和、最大连续数列和、最大间隔环
- 最大连续数列和
- [LeetCode] Maximum Product Subarray 连续数列最大积