首页 > 学院 > 开发设计 > 正文

最大连续数列的和

2019-11-06 07:46:37
字体:
来源:转载
供稿:网友

最大连续数列的和

Time Limit:1000MS  Memory Limit:65536KTotal Submit:139 Accepted:80

Description

 求最大连续子序列的和

Input

 第一行输入n(n<=500),第二行为n个以空格分开的整数(-1000到1000之间);

Output

  该序列中最大的连续子序列的和

Sample Input

 6  1 2 -5 6 7 8

Sample Output

  21

Source

elba

var   i,j,k,l,m,n:longint; begin   readln(n);   read(j);   for i:=2 to n do begin     read(k);     if j>0 then inc(k,j);     if k>m then m:=k;     j:=k;   end;   writeln(m);   readln end.

分析:加到0必做,不是就做

方程:

if j>0 then inc(k,j);     if k>m then m:=k; 


上一篇:最佳浏览路线

下一篇:C#计时器

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表