| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
帮忙看看pascal程序 为何REvar
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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator