2 arr
=array [-5000..5000] of longint;
5 a
,b
:array [-5000..5000] of longint;
6 domino
:array [0..1000] of longint;
9 function min(a
,b
:longint):longint;
11 if a
<b
then exit(a
) else exit(b
);
14 procedure swap(var a
,b
:arr
);
29 for i
:=-5000 to 5000 do begin a
[i
]:=maxint
; b
[i
]:=maxint
; end;
36 b
[j
+domino
[i
]]:=min(a
[j
],b
[j
+domino
[i
]]);
37 b
[j
-domino
[i
]]:=min(a
[j
]+1,b
[j
-domino
[i
]]);
45 if (a
[i
]<>maxint
) or (a
[-i
]<>maxint
) then break
;
46 writeln(min(a
[i
],a
[-i
]));