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

帮忙看看pascal程序 为何RE

Posted by SSLczh at 2010-07-24 23:26:15 on Problem 2576 and last updated at 2010-07-25 11:18:27
var
  n,sum:longint;
  a:array[0..45,0..45010] of boolean;
function change(x:longint):longint;
begin
  if x<0 then change:=-x else change:=x;
end;
procedure dp(x:longint);
var
  i,j:longint;
begin
  for i:=n div 2-1 downto 0 do
    for j:=0 to sum do
      begin
        if a[i,j]
           then if j+x<45010 then a[i+1,j+x]:=true;
      end;
end;
procedure main;
var
  k,ans,i,j:longint;
begin
  while not eof do
    begin
       readln(n);
       sum:=0;
       fillchar(a,sizeof(a),0);
       a[0,0]:=true;
       for i:=1 to n do
         begin
           readln(k);
           sum:=sum+k;
           dp(k);
         end;
       ans:=sum;
       for i:=0 to sum do
         if a[n div 2,i]
            then if change(sum-i*2)<ans
                    then ans:=change(sum-i*2);
       writeln((sum-ans) div 2,' ',(sum-ans) div 2+ans);
    end;
end;
begin
  main;
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