|
|
back to boardHelp Me!!! const max =20; type arr =array [1..max] of longint; var W :arr; xet :array [1..max] of boolean; S,S0, tong,min :longint; N :integer; procedure Sort( var W:arr); var i,j :integer; tg :longint; begin for i:=2 to N do begin tg:=W[i]; j:=i-1; while (j>0)and(W[j]<tg) do begin W[j+1]:=W[j];dec(j);end; W[j+1]:=tg; end; end; procedure ReadInp_Init; var i :integer; begin S0:=0; readln(N); for i:=1 to N do begin readln(W[i]);S0:=S0+W[i];end; S:=S0 div 2; fillchar(xet,sizeof(xet),false); Sort(W); min:=maxlongint; tong:=0; end; procedure Find( k,i:integer); var j :integer; begin for j:=i to N do if (not xet[j])and(tong+W[j]<=S) then begin xet[j]:=true; tong:=tong+W[j]; if (abs(2*tong-S0)<min) then min:=abs(2*tong-S0); Find(k+1,j+1); xet[j]:=false; tong:=tong-W[j]; end; end; BEGIN ReadInp_Init; Find(1,1); Write(min); END. I submited this program but i got WrongAnswer at Test1, while i have correct answer when i test it in my PC, why??? Re: Help Me!!! Idon't know I have same problem const max =20; type arr =array [1..max] of longint; var W :arr; xet :array [1..max] of boolean; S,S0, tong,min :longint; N :integer; procedure Sort( var W:arr); var i,j :integer; tg :longint; begin for i:=2 to N do begin tg:=W[i]; j:=i-1; while (j>0)and(W[j]<tg) do begin W[j+1]:=W[j];dec(j);end; W[j+1]:=tg; end; end; procedure ReadInp_Init; var i :integer; begin S0:=0; readln(N); for i:=1 to N do begin readln(W[i]);S0:=S0+W[i];end; S:=S0 div 2; fillchar(xet,sizeof(xet),false); Sort(W); min:=maxlongint; tong:=0; end; procedure Find( k,i:integer); var j :integer; begin for j:=i to N do if (not xet[j])and(tong+W[j]<=S) then begin xet[j]:=true; tong:=tong+W[j]; if (abs(2*tong-S0)<min) then min:=abs(2*tong-S0); Find(k+1,j+1); xet[j]:=false; tong:=tong-W[j]; end; end; BEGIN ReadInp_Init; Find(1,1); Write(min); END. I submited this program but i got WrongAnswer at Test1, while i have correct answer when i test it in my PC, why??? Re: Help Me!!! Use read insead of readln |
|
|