Horse Jumping problem:
On the half-piece Chinese chess board (8X4), a horse jumps from the lower left corner to the upper right corner. It can only jump to the right, not to the left, ask how many hop solutions are available.
Analysis: This question can be recursive. Standing on a fixed point, you can jump in at most four directions. If the coordinates of the point are x and y, dx = (,), dy =, -1,-2 )(). The recursive boundary is the coordinate point (8, 4) that reaches the target ).
Code
1 // jump horse 01
2 program tiaoma01;
3 const
4 mbx = 8; mby = 4; // coordinates of the target point
5 dx: array [1 .. 4] of integer = (1, 2, 2); // coordinate displacement that can be moved
6 dy: array [1 .. 4] of integer = (2, 1,-1,-2 );
7var
8 num: integer; // number of hop options
9
10 procedure jump (x, y: integer );
11var k, x1, y1: integer;
12 t1, t2, t3: boolean;
13 begin
14 for k: = 1 to 4 do
15 begin
16x1: = x + dx [k];
17 y1: = y + dy [k];
18 t1: = (x1> = 0) and (x1 <= mbx );
19 t2: = (y1> = 0) and (y1 <= mby );
20 t3: = (x1 = mbx) and (y1 = mby );
21 if (t1 and t2) then
22 if t3 then inc (num)
23 else jump (x1, y1); // recursive
24 end;
25end;
26
27 begin
28 num: = 0;
29 jump (0, 0 );
30 writeln (num );
31 readln;
32end.
33
From: crcr Column