Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

这题两个子段是不能连通的,说能连通的都是错的,附AC代码

Posted by huangzhilv at 2011-06-13 23:02:30 on Problem 2593
AC代码:
program poj2479;
const
  maxn=100005;

var
  a:array[1..maxn] of longint;
  l,r:array[0..maxn+1] of longint;
  t,tt,i,n,s,ans:longint;

begin
  readln(n);
  while n<>0 do
  begin
    fillchar(l,sizeof(l),0);
    fillchar(r,sizeof(r),0);
    for i:=1 to n do read(a[i]);
    for i:=1 to n do
      if l[i-1]>=0 then l[i]:=l[i-1]+a[i]
      else l[i]:=a[i];
    for i:=2 to n do
    if l[i-1]>l[i] then l[i]:=l[i-1];

    for i:=n downto 1 do
      if r[i+1]>=0 then r[i]:=r[i+1]+a[i]
    else r[i]:=a[i];
    for i:=n-1 downto 1 do
    if r[i+1]>r[i] then r[i]:=r[i+1];

    ans:=-maxlongint;
    for i:=1 to n-1 do{如果能连通的话应该是从0循环到n才对,但是我试过了,这是错的}
    begin
      s:=l[i]+r[i+1];
      if s>ans then ans:=s;
    end;
    writeln(ans);
    readln(n);
  end;
end.

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator