Horse Jumping Problem

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.