8x8矩阵显示数字程序
Description:
描述:
This is a standard interview problem to fill a matrix with 8 numbers using backtracking.
这是一个标准的面试问题,即使用回溯来用8个数字填充矩阵。
Problem statement:
问题陈述:
A matrix is given to you and eight vacant spaces are there. You have to fill the places with the digits 1 to 8 in a way that there are not any adjacent places filled with its next digits.
将为您提供一个矩阵,那里有八个空位。 您必须以1到8的数字来填充地点,以确保相邻的地方都不会填充其下一个数字。
![Fill 8 numbers in a matrix (1)](https://www.includehelp.com/icp/Images/fill-8-numbers-in-a-matrix-1.jpg)
Input:
An matrix given to you
E.g.
0 -1 -1 0
-1 -1 -1 -1
0 -1 -1 0
Here -1 indicates the vacant places in the matrix.
Output:
Print the matrix with the numbers.
Example
例
If the matrix is this:
0 -1 -1 0
-1 -1 -1 -1
0 -1 -1 0
Output:
0 3 5 0
7 1 8 2
0 4 6 0
![Fill 8 numbers in a matrix (2)](https://i-blog.csdnimg.cn/blog_migrate/1395cb7474e59ea1d7a87612294d7321.png)
Explanation with example
举例说明