|
|
вернуться в форумNo subject DFS why it was wrong..... on test#1 -.- const oo=999999999; var min:longint; stone:array[1..20]of longint; mid:longint; ls,rs:longint; n:longint; procedure readin; var i:longint; tot:longint; begin readln(n); tot:=0; for i:=1 to n do begin readln(stone[i]); tot:=tot+stone[i]; end; mid:=tot div n + 1; ls:=0; rs:=0; end; procedure solve(k:longint); var i:longint; begin if k=n+1 then begin if abs(ls-rs)<min then min:=abs(ls-rs); exit; end; for i:=1 to 2 do begin if i=1 then begin ls:=ls+stone[k]; solve(k+1); ls:=ls-stone[k]; end; if i=2 then begin rs:=rs+stone[k]; solve(k+1); rs:=rs-stone[k]; end; end; end; begin min:=oo; readin(); solve(1); writeln(min); end. |
|
|