简体   繁体   English

3D迷宫编程

[英]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). 迷宫是尺寸为NxNxN(长度=宽度=高度= 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. 下图显示了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. 在数学上正确,向前和向上分别定义为x,y和z轴上坐标的正向变化。

Example: For, N=1, the grid structure and solution is shown below: 示例:对于N = 1,网格结构和解决方案如下所示:

在此处输入图片说明

Thus, for N=1, we have a net of 6 ways. 因此,对于N = 1,我们有6种方式的网络。 Input Format: Single integer N 输入格式:单整数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. 为了摆脱蚂蚁,需要使N向右移动,N向上方移动,N向前方移动。

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. R,U和F移动的每个不同顺序都是不同的路径,因此答案是由N Rs,Us和Fs组成的不同字符串的数量。

That can be simply calculated as (3N)! / (N!)^3 可以简单地计算为(3N)! / (N!)^3 (3N)! / (N!)^3 . (3N)! / (N!)^3

... where ! ...哪里! is factorial, not Boolean negation, and ^ is exponential, not XOR :) 是阶乘,不是布尔取反, ^是指数,而不是XOR :)

It is basically the same as 2d puzzles but more intersections. 它与2D拼图基本相同,但交叉点更多。 Use BFS or DFS algorithms. 使用BFS或DFS算法。 Good Luck 祝好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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