简体   繁体   中英

3d Maze Programming

I am trying to solve this.

I don't need the entire code or logic. Just need some hint to get me started on the problem.What method should I apply on this problem.

PROBLEM

Suppose, an ant is trapped in a maze, with only one way in and one way out. The maze is a cubiclattice like structure of dimension NxNxN (Length=Breadth=Height=N). The way in is the leftbottom most point, and the way out is the right topmost point (along the principal diagonal). The below picture shows the maze for N=2.

在此处输入图片说明

Assuming the ant only moves right, forward or upwards along the grids of the maze, calculate the total number of ways in which the ant can escape. Mathematically right, forward and upwards are defined at positive changes in coordinates on x, y and z axes respectively.

Example: For, N=1, the grid structure and solution is shown below:

在此处输入图片说明

Thus, for N=1, we have a net of 6 ways. Input Format: Single integer N

Output Format: Output also consists of a single number corresponding to the number of ways the ant can escape the maze.

Constraints:

  • 0<N<=8

在此处输入图片说明

To get out the ant needs to make N moves right, N moves up, and N moves forward.

Since no paths are blocked, these moves can be made in any order without restriction.

Every different ordering of R, U, and F moves is a different path, so the answer is the number of distinct strings consisting of N Rs, Us, and Fs.

That can be simply calculated as (3N)! / (N!)^3 (3N)! / (N!)^3 .

... where ! is factorial, not Boolean negation, and ^ is exponential, not XOR :)

It is basically the same as 2d puzzles but more intersections. Use BFS or DFS algorithms. Good Luck

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM