在 NxN 棋盘
上打印所有可能的骑士之旅起点
原文:https://www . geeksforgeeks . org/print-all-knights-tour-从一个可能的起点出发-on-nxn-棋盘/
给定一个 N x N 棋盘,一个骑士最初站在 X 第T5】行和 Y 第T9】列上,任务是打印所有可能的路径,这样骑士必须精确地访问每个方块一次。****
示例:
输入: N = 5,X = 1,Y = 1 输出: 1 6 15 10 21 14 9 20 5 16 19 2 7 22 11 8 13 24 17 4 25 18 3 12 23 1 6 11 18 21 12 17 20 5 10 7 2 15 22 19【T13
……302 更 说明:最初,骑士在(1,2) 第号牢房。按照第 1 条路径,骑士将按照以下顺序访问细胞:(1,1)-(T5】(3,2)-(T6】(5,3)-(T7】(4,5)-(T8】(2,4)……以此类推。
输入: N = 3,X = 1,Y = 3 输出: -1 解释:不存在有效的路径序列,使得骑士只访问每个广场一次。
方法:通过递归和回溯的帮助,逐一生成所有可能的行程并检查是否满足给定条件,可以解决问题。在骑士之旅问题中讨论了类似方法的更彻底的解释。以下是要遵循的步骤:
- 创建一个递归函数来迭代骑士可以遵循的所有可能路径。
- 使用变量保持骑士访问的方块数。
- 创建一个函数 isSafe() ,该函数以一个正方形的坐标为参数,返回该正方形对于下一个骑士的移动是否有效。
- 迭代骑士所有可能的 8 个动作,检查它们是否可以安全访问。如果是,递归调用下一步,直到访问的方块数等于方块总数。
下面是上述方法的实现:
C++
// C++ program of the above approach
#include <bits/stdc++.h>
using namespace std;
// Stores the 8 possible combinations of
// moves that the knight can follow
int DirX[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int DirY[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
// Function to find if (i, j) is a valid
// cell for the knight to move and it
// exists within the chessboard
bool isSafe(int i, int j, int n,
vector<vector<int> >& Board)
{
return (i >= 0 and j >= 0 and i < n and j < n
and Board[i][j] == 0);
}
// Stores whether there exist any valid path
bool isPossible = false;
// Recursive function to iterate through all
// the paths that the knight can follow
void knightTour(vector<vector<int> >& ChessBoard, int N,
int x, int y, int visited = 1)
{
// Mark the current square of the chessboard
ChessBoard[x][y] = visited;
// If the number of visited squares are equal
// to the total number of sqares
if (visited == N * N) {
isPossible = true;
// Print the current state of ChessBoard
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
cout << ChessBoard[i][j] << " ";
}
cout << endl;
}
cout << endl;
// Backtrack to the previous move
ChessBoard[x][y] = 0;
return;
}
// Iterate through all the eight possible moves
// for a knight
for (int i = 0; i < 8; i++) {
// Stores the new position of the knight
// after a move
int newX = x + DirX[i];
int newY = y + DirY[i];
// If the new position is a valid position
// recursively call for the next move
if (isSafe(newX, newY, N, ChessBoard)
&& !ChessBoard[newX][newY]) {
knightTour(ChessBoard, N, newX, newY,
visited + 1);
}
}
// Backtrack to the previous move
ChessBoard[x][y] = 0;
}
// Driver Code
int main()
{
vector<vector<int> > ChessBoard(5, vector<int>(5, 0));
int N = ChessBoard.size();
int X = 1;
int Y = 1;
knightTour(ChessBoard, N, X - 1, Y - 1);
// If no valid sequence of moves exist
if (!isPossible) {
cout << -1;
}
return 0;
}
Java 语言(一种计算机语言,尤用于创建网站)
// Java program of the above approach
class GFG {
// Stores the 8 possible combinations of
// moves that the knight can follow
static int[] DirX = { 2, 1, -1, -2, -2, -1, 1, 2 };
static int[] DirY = { 1, 2, 2, 1, -1, -2, -2, -1 };
// Function to find if (i, j) is a valid
// cell for the knight to move and it
// exists within the chessboard
static boolean isSafe(int i, int j, int n, int[][] Board) {
return (i >= 0 && j >= 0 && i < n && j < n && Board[i][j] == 0);
}
// Stores whether there exist any valid path
static boolean isPossible = false;
// Recursive function to iterate through all
// the paths that the knight can follow
static void knightTour(int[][] ChessBoard, int N, int x, int y, int visited)
{
// Mark the current square of the chessboard
ChessBoard[x][y] = visited;
// If the number of visited squares are equal
// to the total number of sqares
if (visited == N * N) {
isPossible = true;
// Print the current state of ChessBoard
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
System.out.print(ChessBoard[i][j] + " ");
}
System.out.println();
}
System.out.println();
// Backtrack to the previous move
ChessBoard[x][y] = 0;
return;
}
// Iterate through all the eight possible moves
// for a knight
for (int i = 0; i < 8; i++) {
// Stores the new position of the knight
// after a move
int newX = x + DirX[i];
int newY = y + DirY[i];
// If the new position is a valid position
// recursively call for the next move
if (isSafe(newX, newY, N, ChessBoard)
&& ChessBoard[newX][newY] == 0) {
knightTour(ChessBoard, N, newX, newY,
visited + 1);
}
}
// Backtrack to the previous move
ChessBoard[x][y] = 0;
}
// Driver Code
public static void main(String args[]) {
int[][] ChessBoard = new int[5][5];
int N = ChessBoard.length;
int X = 1;
int Y = 1;
knightTour(ChessBoard, N, X - 1, Y - 1, 1);
// If no valid sequence of moves exist
if (isPossible == false) {
System.out.println(-1);
}
}
}
// This code is contributed by Saurabh Jaiswal
C
// C# program of the above approach
using System;
class GFG {
// Stores the 8 possible combinations of
// moves that the knight can follow
static int[] DirX = { 2, 1, -1, -2, -2, -1, 1, 2 };
static int[] DirY = { 1, 2, 2, 1, -1, -2, -2, -1 };
// Function to find if (i, j) is a valid
// cell for the knight to move and it
// exists within the chessboard
static bool isSafe(int i, int j, int n, int[, ] Board)
{
return (i >= 0 && j >= 0 && i < n && j < n
&& Board[i, j] == 0);
}
// Stores whether there exist any valid path
static bool isPossible = false;
// Recursive function to iterate through all
// the paths that the knight can follow
static void knightTour(int[, ] ChessBoard, int N, int x,
int y, int visited = 1)
{
// Mark the current square of the chessboard
ChessBoard[x, y] = visited;
// If the number of visited squares are equal
// to the total number of sqares
if (visited == N * N) {
isPossible = true;
// Print the current state of ChessBoard
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
Console.Write(ChessBoard[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
// Backtrack to the previous move
ChessBoard[x, y] = 0;
return;
}
// Iterate through all the eight possible moves
// for a knight
for (int i = 0; i < 8; i++) {
// Stores the new position of the knight
// after a move
int newX = x + DirX[i];
int newY = y + DirY[i];
// If the new position is a valid position
// recursively call for the next move
if (isSafe(newX, newY, N, ChessBoard)
&& ChessBoard[newX, newY] == 0) {
knightTour(ChessBoard, N, newX, newY,
visited + 1);
}
}
// Backtrack to the previous move
ChessBoard[x, y] = 0;
}
// Driver Code
public static void Main()
{
int[, ] ChessBoard = new int[5, 5];
int N = ChessBoard.GetLength(0);
int X = 1;
int Y = 1;
knightTour(ChessBoard, N, X - 1, Y - 1);
// If no valid sequence of moves exist
if (isPossible == false) {
Console.WriteLine(-1);
}
}
}
// This code is contributed by ukasp.
java 描述语言
<script>
// Javascript program of the above approach
// Stores the 8 possible combinations of
// moves that the knight can follow
let DirX = [2, 1, -1, -2, -2, -1, 1, 2];
let DirY = [1, 2, 2, 1, -1, -2, -2, -1];
// Function to find if (i, j) is a valid
// cell for the knight to move and it
// exists within the chessboard
function isSafe(i, j, n, Board) {
return i >= 0 && j >= 0 && i < n && j < n && Board[i][j] == 0;
}
// Stores whether there exist any valid path
let isPossible = false;
// Recursive function to iterate through all
// the paths that the knight can follow
function knightTour(ChessBoard, N, x, y, visited = 1) {
// Mark the current square of the chessboard
ChessBoard[x][y] = visited;
// If the number of visited squares are equal
// to the total number of sqares
if (visited == N * N) {
isPossible = true;
// Prlet the current state of ChessBoard
for (let i = 0; i < N; i++) {
for (let j = 0; j < N; j++) {
document.write(ChessBoard[i][j] + " ");
}
document.write("<br>");
}
document.write("<br>");
// Backtrack to the previous move
ChessBoard[x][y] = 0;
return;
}
// Iterate through all the eight possible moves
// for a knight
for (let i = 0; i < 8; i++) {
// Stores the new position of the knight
// after a move
let newX = x + DirX[i];
let newY = y + DirY[i];
// If the new position is a valid position
// recursively call for the next move
if (isSafe(newX, newY, N, ChessBoard) && !ChessBoard[newX][newY]) {
knightTour(ChessBoard, N, newX, newY, visited + 1);
}
}
// Backtrack to the previous move
ChessBoard[x][y] = 0;
}
// Driver Code
let ChessBoard = new Array(5).fill(0).map(() => new Array(5).fill(0));
let N = ChessBoard.length;
let X = 1;
let Y = 1;
knightTour(ChessBoard, N, X - 1, Y - 1);
// If no valid sequence of moves exist
if (!isPossible) {
document.write("-1");
}
</script>
Output
1 6 15 10 21
14 9 20 5 16
19 2 7 22 11
8 13 24 17 4
25 18 3 12 23
1 6 11 18 21
12 17 20 5 10
7 2 15 22 19
16 13 24 9 4
25 8 3 14 23
1 6 11 16 21
12 15 20 5 10
7 2 13 22 17
14 19 24 9 4
25 8 3 18 23
1 6 17 12 21
16 11 20 5 18
7 2 9 22 13
10 15 24 19 4
25 8 3 14 23
1 12 17 6 21
18 5 20 11 16
13 2 9 22 7
4 19 24 15 10
25 14 3 8 23
1 16 11 6 21
10 5 20 15 12
17 2 13 22 7
4 9 24 19 14
25 18 3 8 23
1 18 11 6 21
10 5 20 17 12
19 2 15 22 7
4 9 24 13 16
25 14 3 8 23
1 10 15 6 21
16 5 20 9 14
11 2 7 22 19
4 17 24 13 8
25 12 3 18 23
1 16 5 10 21
6 11 20 15 4
19 2 17 22 9
12 7 24 3 14
25 18 13 8 23
1 12 5 18 21
6 17 20 13 4
11 2 9 22 19
16 7 24 3 14
25 10 15 8 23
1 10 5 16 21
6 15 20 11 4
9 2 7 22 17
14 19 24 3 12
25 8 13 18 23
1 18 7 12 21
8 13 20 17 6
19 2 5 22 11
14 9 24 3 16
25 4 15 10 23
1 6 17 12 21
18 11 20 7 16
5 2 15 22 13
10 19 24 3 8
25 4 9 14 23
1 6 15 12 21
16 11 20 7 14
5 2 13 22 19
10 17 24 3 8
25 4 9 18 23
1 12 17 8 21
18 7 20 3 16
13 2 11 22 9
6 19 24 15 4
25 14 5 10 23
1 16 13 8 21
12 7 20 3 14
17 2 15 22 9
6 11 24 19 4
25 18 5 10 23
1 18 13 8 21
12 7 20 3 14
19 2 17 22 9
6 11 24 15 4
25 16 5 10 23
1 10 15 8 21
16 7 20 3 14
11 2 9 22 19
6 17 24 13 4
25 12 5 18 23
1 4 15 10 21
14 9 20 3 16
19 2 5 22 11
8 13 24 17 6
25 18 7 12 23
1 4 9 18 21
10 17 20 3 8
5 2 13 22 19
16 11 24 7 14
25 6 15 12 23
1 4 9 16 21
10 15 20 3 8
5 2 11 22 17
14 19 24 7 12
25 6 13 18 23
1 4 17 12 21
16 11 20 3 18
5 2 7 22 13
10 15 24 19 8
25 6 9 14 23
1 16 3 10 21
6 11 20 15 4
17 2 5 22 9
12 7 24 19 14
25 18 13 8 23
1 18 3 12 21
8 13 20 17 4
19 2 7 22 11
14 9 24 5 16
25 6 15 10 23
1 8 3 14 21
18 13 20 9 4
7 2 17 22 15
12 19 24 5 10
25 6 11 16 23
1 8 3 14 21
16 13 20 9 4
7 2 15 22 19
12 17 24 5 10
25 6 11 18 23
1 14 3 8 21
4 9 20 13 16
19 2 15 22 7
10 5 24 17 12
25 18 11 6 23
1 14 3 8 21
4 9 20 13 18
15 2 17 22 7
10 5 24 19 12
25 16 11 6 23
1 12 3 18 21
4 17 20 13 8
11 2 7 22 19
16 5 24 9 14
25 10 15 6 23
1 10 3 16 21
4 15 20 11 6
9 2 5 22 17
14 19 24 7 12
25 8 13 18 23
1 22 11 16 7
12 17 8 21 10
25 2 23 6 15
18 13 4 9 20
3 24 19 14 5
1 22 11 16 7
12 17 8 21 10
23 2 25 6 15
18 13 4 9 20
3 24 19 14 5
1 24 11 16 7
12 17 8 25 10
23 2 21 6 15
18 13 4 9 20
3 22 19 14 5
1 22 11 16 7
12 17 8 23 10
21 2 19 6 15
18 13 4 9 24
3 20 25 14 5
1 20 11 16 7
12 25 8 21 10
19 2 17 6 15
24 13 4 9 22
3 18 23 14 5
1 18 11 24 7
12 23 8 19 10
17 2 15 6 25
22 13 4 9 20
3 16 21 14 5
1 16 11 22 7
12 21 8 17 10
15 2 13 6 23
20 25 4 9 18
3 14 19 24 5
1 14 25 20 7
24 19 8 15 10
13 2 11 6 21
18 23 4 9 16
3 12 17 22 5
1 24 13 18 7
14 19 8 23 12
25 2 11 6 17
20 15 4 9 22
3 10 21 16 5
1 12 15 20 7
16 21 8 25 14
11 2 13 6 19
22 17 4 9 24
3 10 23 18 5
1 12 17 22 7
18 23 8 13 16
11 2 15 6 21
24 19 4 9 14
3 10 25 20 5
1 12 19 24 7
20 25 8 13 18
11 2 17 6 23
16 21 4 9 14
3 10 15 22 5
1 12 23 18 7
24 17 8 13 22
11 2 21 6 19
16 25 4 9 14
3 10 15 20 5
1 12 25 18 7
22 17 8 13 24
11 2 23 6 19
16 21 4 9 14
3 10 15 20 5
1 12 23 18 7
22 17 8 13 24
11 2 25 6 19
16 21 4 9 14
3 10 15 20 5
1 12 21 18 7
22 17 8 13 20
11 2 19 6 25
16 23 4 9 14
3 10 15 24 5
1 16 21 10 7
20 11 8 15 22
25 2 17 6 9
12 19 4 23 14
3 24 13 18 5
1 16 21 10 7
22 11 8 15 20
17 2 25 6 9
12 23 4 19 14
3 18 13 24 5
1 16 21 10 7
22 11 8 15 20
17 2 23 6 9
12 25 4 19 14
3 18 13 24 5
1 16 25 10 7
24 11 8 15 20
17 2 21 6 9
12 23 4 19 14
3 18 13 22 5
1 16 23 10 7
22 11 8 15 24
17 2 19 6 9
12 21 4 25 14
3 18 13 20 5
1 24 19 10 7
18 11 8 25 20
23 2 15 6 9
12 17 4 21 14
3 22 13 16 5
1 22 17 10 7
16 11 8 23 18
21 2 13 6 9
12 15 4 19 24
3 20 25 14 5
1 20 15 10 7
14 25 8 21 16
19 2 11 6 9
24 13 4 17 22
3 18 23 12 5
1 18 23 12 7
24 13 8 17 22
19 2 11 6 9
14 25 4 21 16
3 20 15 10 5
1 20 25 14 7
12 15 8 19 24
21 2 13 6 9
16 11 4 23 18
3 22 17 10 5
1 22 13 16 7
12 17 8 21 14
23 2 15 6 9
18 11 4 25 20
3 24 19 10 5
1 24 13 18 7
12 19 8 23 14
25 2 17 6 9
20 11 4 15 22
3 16 21 10 5
1 18 13 20 7
12 21 8 25 14
17 2 19 6 9
22 11 4 15 24
3 16 23 10 5
1 18 13 22 7
12 23 8 19 14
17 2 21 6 9
24 11 4 15 20
3 16 25 10 5
1 18 13 24 7
12 25 8 19 14
17 2 23 6 9
22 11 4 15 20
3 16 21 10 5
1 18 13 24 7
12 23 8 19 14
17 2 25 6 9
22 11 4 15 20
3 16 21 10 5
1 24 13 18 7
14 19 8 23 12
9 2 25 6 17
20 15 4 11 22
3 10 21 16 5
1 24 13 18 7
14 19 8 25 12
9 2 23 6 17
20 15 4 11 22
3 10 21 16 5
1 22 13 18 7
14 19 8 23 12
9 2 21 6 17
20 15 4 11 24
3 10 25 16 5
1 20 13 18 7
14 25 8 21 12
9 2 19 6 17
24 15 4 11 22
3 10 23 16 5
1 18 13 24 7
14 23 8 19 12
9 2 17 6 25
22 15 4 11 20
3 10 21 16 5
1 16 13 22 7
14 21 8 17 12
9 2 15 6 23
20 25 4 11 18
3 10 19 24 5
1 14 25 20 7
24 19 8 15 12
9 2 13 6 21
18 23 4 11 16
3 10 17 22 5
1 12 23 18 7
22 17 8 13 24
9 2 11 6 19
16 21 4 25 14
3 10 15 20 5
1 10 15 20 7
16 21 8 25 14
9 2 11 6 19
22 17 4 13 24
3 12 23 18 5
1 10 17 22 7
18 23 8 11 16
9 2 13 6 21
24 19 4 15 12
3 14 25 20 5
1 10 19 24 7
20 25 8 11 18
9 2 15 6 23
14 21 4 17 12
3 16 13 22 5
1 10 23 16 7
24 15 8 11 22
9 2 19 6 17
14 25 4 21 12
3 20 13 18 5
1 10 25 16 7
20 15 8 11 24
9 2 21 6 17
14 19 4 23 12
3 22 13 18 5
1 10 21 16 7
20 15 8 11 22
9 2 23 6 17
14 19 4 25 12
3 24 13 18 5
1 10 21 16 7
20 15 8 11 22
9 2 25 6 17
14 19 4 23 12
3 24 13 18 5
1 10 21 16 7
22 15 8 11 20
9 2 17 6 25
14 23 4 19 12
3 18 13 24 5
1 18 21 12 7
20 13 8 17 22
25 2 19 6 11
14 9 4 23 16
3 24 15 10 5
1 18 23 12 7
24 13 8 17 22
19 2 25 6 11
14 9 4 21 16
3 20 15 10 5
1 18 25 12 7
24 13 8 17 22
19 2 23 6 11
14 9 4 21 16
3 20 15 10 5
1 18 23 12 7
22 13 8 17 24
19 2 21 6 11
14 9 4 25 16
3 20 15 10 5
1 24 19 12 7
18 13 8 25 20
23 2 17 6 11
14 9 4 21 16
3 22 15 10 5
1 22 17 12 7
16 13 8 23 18
21 2 15 6 11
14 9 4 19 24
3 20 25 10 5
1 20 15 12 7
14 25 8 21 16
19 2 13 6 11
24 9 4 17 22
3 18 23 10 5
1 18 13 24 7
12 23 8 19 14
17 2 11 6 25
22 9 4 15 20
3 16 21 10 5
1 20 25 14 7
10 15 8 19 24
21 2 11 6 13
16 9 4 23 18
3 22 17 12 5
1 22 11 16 7
10 17 8 21 12
23 2 13 6 15
18 9 4 25 20
3 24 19 14 5
1 24 11 18 7
10 19 8 23 12
25 2 15 6 17
20 9 4 13 22
3 14 21 16 5
1 16 11 20 7
10 21 8 25 12
15 2 17 6 19
22 9 4 13 24
3 14 23 18 5
1 16 11 22 7
10 23 8 17 12
15 2 19 6 21
24 9 4 13 18
3 14 25 20 5
1 16 11 24 7
10 25 8 17 12
15 2 21 6 23
20 9 4 13 18
3 14 19 22 5
1 16 11 22 7
10 21 8 17 12
15 2 25 6 23
20 9 4 13 18
3 14 19 24 5
1 16 11 22 7
10 21 8 17 12
15 2 23 6 25
20 9 4 13 18
3 14 19 24 5
1 20 7 14 25
10 15 24 19 8
21 2 9 6 13
16 11 4 23 18
3 22 17 12 5
1 22 7 16 25
12 17 24 21 8
23 2 11 6 15
18 13 4 9 20
3 10 19 14 5
1 12 7 18 25
22 17 24 13 8
11 2 21 6 19
16 23 4 9 14
3 10 15 20 5
1 12 7 18 25
20 17 24 13 8
11 2 19 6 23
16 21 4 9 14
3 10 15 22 5
1 18 7 12 25
8 13 24 17 20
23 2 19 6 11
14 9 4 21 16
3 22 15 10 5
1 18 7 12 25
8 13 24 17 22
19 2 21 6 11
14 9 4 23 16
3 20 15 10 5
1 16 7 22 25
8 21 24 17 12
15 2 11 6 23
20 9 4 13 18
3 14 19 10 5
1 14 7 20 25
8 19 24 15 10
13 2 9 6 21
18 23 4 11 16
3 12 17 22 5
1 16 21 8 25
22 7 24 15 20
17 2 11 6 9
12 23 4 19 14
3 18 13 10 5
1 20 13 8 25
12 7 24 19 14
21 2 15 6 9
16 11 4 23 18
3 22 17 10 5
1 22 13 8 25
12 7 24 21 14
23 2 17 6 9
18 11 4 15 20
3 16 19 10 5
1 14 19 8 25
20 7 24 13 18
15 2 9 6 23
10 21 4 17 12
3 16 11 22 5
1 12 19 14 25
18 7 24 11 20
23 2 13 6 15
8 17 4 21 10
3 22 9 16 5
1 12 17 22 25
18 7 24 11 16
13 2 21 6 23
8 19 4 15 10
3 14 9 20 5
1 12 17 20 25
18 7 24 11 16
13 2 19 6 21
8 23 4 15 10
3 14 9 22 5
1 12 21 16 25
20 7 24 11 22
13 2 15 6 17
8 19 4 23 10
3 14 9 18 5
1 16 19 10 25
18 11 24 15 20
23 2 17 6 9
12 7 4 21 14
3 22 13 8 5
1 16 21 10 25
20 11 24 15 22
17 2 19 6 9
12 7 4 23 14
3 18 13 8 5
1 16 11 22 25
10 21 24 17 12
15 2 9 6 23
20 7 4 13 18
3 14 19 8 5
1 20 9 14 25
8 15 24 19 10
21 2 11 6 13
16 7 4 23 18
3 22 17 12 5
1 22 9 16 25
8 17 24 21 10
23 2 13 6 15
18 7 4 11 20
3 12 19 14 5
1 14 9 20 25
8 19 24 15 10
13 2 21 6 23
18 7 4 11 16
3 12 17 22 5
1 10 19 14 25
18 13 24 9 20
23 2 11 6 15
12 17 4 21 8
3 22 7 16 5
1 10 15 22 25
16 21 24 9 14
11 2 19 6 23
20 17 4 13 8
3 12 7 18 5
1 10 15 20 25
16 19 24 9 14
11 2 17 6 21
18 23 4 13 8
3 12 7 22 5
1 10 21 16 25
20 15 24 9 22
11 2 13 6 17
14 19 4 23 8
3 12 7 18 5
1 16 21 10 25
22 9 24 15 20
17 2 13 6 11
8 23 4 19 14
3 18 7 12 5
1 20 15 10 25
14 9 24 19 16
21 2 17 6 11
8 13 4 23 18
3 22 7 12 5
1 22 15 10 25
14 9 24 21 16
23 2 19 6 11
8 13 4 17 20
3 18 7 12 5
1 14 19 10 25
20 9 24 13 18
15 2 11 6 23
8 21 4 17 12
3 16 7 22 5
1 12 17 6 23
16 7 22 11 18
21 2 13 24 5
8 15 4 19 10
3 20 9 14 25
1 12 17 6 23
18 7 22 11 16
13 2 19 24 5
8 21 4 15 10
3 14 9 20 25
1 12 19 6 23
18 7 22 11 20
13 2 15 24 5
8 17 4 21 10
3 14 9 16 25
1 14 19 8 23
20 9 22 13 18
15 2 7 24 5
10 21 4 17 12
3 16 11 6 25
1 18 9 12 23
8 13 22 17 10
19 2 11 24 5
14 7 4 21 16
3 20 15 6 25
1 20 9 14 23
8 15 22 19 10
21 2 13 24 5
16 7 4 11 18
3 12 17 6 25
1 14 19 10 23
20 9 22 5 18
15 2 13 24 11
8 21 4 17 6
3 16 7 12 25
1 18 15 10 23
14 9 22 5 16
19 2 17 24 11
8 13 4 21 6
3 20 7 12 25
1 20 15 10 23
14 9 22 5 16
21 2 19 24 11
8 13 4 17 6
3 18 7 12 25
1 12 17 10 23
18 9 22 5 16
13 2 11 24 21
8 19 4 15 6
3 14 7 20 25
1 6 17 12 23
16 11 22 5 18
21 2 7 24 13
10 15 4 19 8
3 20 9 14 25
1 6 11 20 23
12 19 22 5 10
7 2 15 24 21
18 13 4 9 16
3 8 17 14 25
1 6 11 18 23
12 17 22 5 10
7 2 13 24 19
16 21 4 9 14
3 8 15 20 25
1 6 19 14 23
18 13 22 5 20
7 2 9 24 15
12 17 4 21 10
3 8 11 16 25
1 14 19 6 23
20 5 22 13 18
15 2 9 24 7
10 21 4 17 12
3 16 11 8 25
1 18 11 6 23
10 5 22 17 12
19 2 13 24 7
14 9 4 21 16
3 20 15 8 25
1 20 11 6 23
10 5 22 19 12
21 2 15 24 7
16 9 4 13 18
3 14 17 8 25
1 12 17 6 23
18 5 22 11 16
13 2 7 24 21
8 19 4 15 10
3 14 9 20 25
1 10 17 12 23
16 5 22 9 18
21 2 11 24 13
6 15 4 19 8
3 20 7 14 25
1 10 15 20 23
16 5 22 9 14
11 2 19 24 21
6 17 4 13 8
3 12 7 18 25
1 10 15 18 23
16 5 22 9 14
11 2 17 24 19
6 21 4 13 8
3 12 7 20 25
1 10 19 14 23
18 5 22 9 20
11 2 13 24 15
6 17 4 21 8
3 12 7 16 25
1 14 9 20 23
10 19 22 15 8
5 2 13 24 21
18 11 4 7 16
3 6 17 12 25
1 12 9 18 23
10 17 22 13 8
5 2 11 24 19
16 21 4 7 14
3 6 15 20 25
1 8 19 14 23
18 13 22 9 20
5 2 7 24 15
12 17 4 21 10
3 6 11 16 25
1 6 19 12 23
20 11 22 7 18
5 2 15 24 13
10 21 4 17 8
3 16 9 14 25
1 6 17 12 23
16 11 22 7 18
5 2 19 24 13
10 15 4 21 8
3 20 9 14 25
1 6 17 12 23
18 11 22 7 16
5 2 13 24 21
10 19 4 15 8
3 14 9 20 25
1 18 5 10 25
6 11 2 19 4
17 20 15 24 9
12 7 22 3 14
21 16 13 8 23
1 16 5 10 25
6 11 2 17 4
15 20 13 24 9
12 7 22 3 18
21 14 19 8 23
1 8 19 14 25
18 13 2 9 4
7 20 5 24 15
12 17 22 3 10
21 6 11 16 23
1 6 9 14 25
10 15 2 19 8
5 20 7 24 13
16 11 22 3 18
21 4 17 12 23
1 6 11 16 25
12 17 2 7 10
5 20 9 24 15
18 13 22 3 8
21 4 19 14 23
1 6 19 12 25
16 11 2 7 18
5 20 17 24 13
10 15 22 3 8
21 4 9 14 23
1 10 19 4 25
18 5 2 9 14
11 20 15 24 3
6 17 22 13 8
21 12 7 16 23
1 10 17 4 25
16 5 2 9 18
11 20 13 24 3
6 15 22 19 8
21 12 7 14 23
1 18 13 4 25
12 5 2 19 14
17 20 9 24 3
6 11 22 15 8
21 16 7 10 23
1 16 11 4 25
10 5 2 17 12
15 20 7 24 3
6 9 22 13 18
21 14 19 8 23
1 14 19 8 25
6 9 2 13 18
15 20 7 24 3
10 5 22 17 12
21 16 11 4 23
1 16 7 10 25
6 11 2 15 8
17 20 9 24 3
12 5 22 19 14
21 18 13 4 23
1 12 7 14 25
6 15 2 19 8
11 20 13 24 3
16 5 22 9 18
21 10 17 4 23
1 12 7 16 25
6 17 2 13 8
11 20 15 24 3
18 5 22 9 14
21 10 19 4 23
1 14 23 8 3
22 9 2 13 18
15 24 19 4 7
10 21 6 17 12
25 16 11 20 5
1 14 21 8 3
20 9 2 13 22
15 24 17 4 7
10 19 6 23 12
25 16 11 18 5
1 22 17 8 3
16 9 2 23 18
21 24 13 4 7
10 15 6 19 12
25 20 11 14 5
1 20 15 8 3
14 9 2 21 16
19 24 11 4 7
10 13 6 17 22
25 18 23 12 5
1 18 23 12 3
10 13 2 17 22
19 24 11 4 7
14 9 6 21 16
25 20 15 8 5
1 20 11 14 3
10 15 2 19 12
21 24 13 4 7
16 9 6 23 18
25 22 17 8 5
1 16 11 18 3
10 19 2 23 12
15 24 17 4 7
20 9 6 13 22
25 14 21 8 5
1 16 11 20 3
10 21 2 17 12
15 24 19 4 7
22 9 6 13 18
25 14 23 8 5
1 10 15 20 3
16 21 2 7 14
11 24 9 4 19
22 17 6 13 8
25 12 23 18 5
1 18 23 12 3
16 11 2 7 22
19 24 17 4 13
10 15 6 21 8
25 20 9 14 5
1 20 17 12 3
16 11 2 7 18
21 24 19 4 13
10 15 6 23 8
25 22 9 14 5
1 8 13 18 3
14 19 2 7 12
9 24 21 4 17
20 15 6 11 22
25 10 23 16 5
1 8 23 18 3
22 17 2 7 12
9 24 13 4 19
16 21 6 11 14
25 10 15 20 5
1 8 21 16 3
20 15 2 7 22
9 24 11 4 17
14 19 6 23 12
25 10 13 18 5
1 18 23 8 3
12 7 2 17 22
19 24 13 4 9
14 11 6 21 16
25 20 15 10 5
1 20 13 8 3
12 7 2 19 14
21 24 15 4 9
16 11 6 23 18
25 22 17 10 5
1 18 13 8 3
12 7 2 23 14
17 24 19 4 9
20 11 6 15 22
25 16 21 10 5
1 18 13 8 3
12 7 2 19 14
17 24 21 4 9
22 11 6 15 20
25 16 23 10 5
1 12 23 18 3
22 7 2 11 16
13 24 17 4 19
8 21 6 15 10
25 14 9 20 5
1 12 21 16 3
20 7 2 11 22
13 24 15 4 17
8 19 6 23 10
25 14 9 18 5
1 22 17 12 3
16 7 2 23 18
21 24 11 4 13
8 15 6 19 10
25 20 9 14 5
1 20 15 10 3
14 7 2 21 16
19 24 9 4 11
8 13 6 17 22
25 18 23 12 5
1 22 11 16 3
12 17 2 23 10
7 24 21 4 15
18 13 6 9 20
25 8 19 14 5
1 20 11 16 3
12 17 2 21 10
7 24 19 4 15
18 13 6 9 22
25 8 23 14 5
1 12 23 18 3
22 17 2 13 10
7 24 11 4 19
16 21 6 9 14
25 8 15 20 5
1 10 21 16 3
20 15 2 11 22
7 24 9 4 17
14 19 6 23 12
25 8 13 18 5
1 8 13 18 3
14 19 2 23 12
7 24 9 4 17
20 15 6 11 22
25 10 21 16 5
1 8 15 20 3
16 21 2 9 14
7 24 11 4 19
22 17 6 13 10
25 12 23 18 5
1 8 23 14 3
18 13 2 9 22
7 24 19 4 15
12 17 6 21 10
25 20 11 16 5
1 8 19 14 3
18 13 2 9 20
7 24 21 4 15
12 17 6 23 10
25 22 11 16 5
1 12 21 16 3
20 15 2 11 22
25 8 13 4 17
14 19 6 23 10
7 24 9 18 5
1 12 17 22 3
18 23 2 11 16
13 8 25 4 21
24 19 6 15 10
7 14 9 20 5
1 12 17 22 3
18 25 2 11 16
13 8 23 4 21
24 19 6 15 10
7 14 9 20 5
1 12 17 24 3
18 23 2 11 16
13 8 21 4 25
22 19 6 15 10
7 14 9 20 5
1 12 17 22 3
18 21 2 11 16
13 8 19 4 23
20 25 6 15 10
7 14 9 24 5
1 12 25 20 3
24 19 2 11 16
13 8 17 4 21
18 23 6 15 10
7 14 9 22 5
1 12 23 18 3
22 17 2 11 24
13 8 15 4 19
16 21 6 25 10
7 14 9 20 5
1 24 19 14 3
18 13 2 25 20
23 8 11 4 15
12 17 6 21 10
7 22 9 16 5
1 14 19 24 3
20 25 2 13 18
15 8 11 4 23
10 21 6 17 12
7 16 9 22 5
1 18 23 12 3
24 11 2 17 22
19 8 15 4 13
10 25 6 21 16
7 20 9 14 5
1 20 25 12 3
16 11 2 19 24
21 8 17 4 13
10 15 6 23 18
7 22 9 14 5
1 22 17 12 3
16 11 2 21 18
23 8 19 4 13
10 15 6 25 20
7 24 9 14 5
1 24 17 12 3
16 11 2 23 18
25 8 21 4 13
10 15 6 19 22
7 20 9 14 5
1 22 17 12 3
16 11 2 25 18
21 8 23 4 13
10 15 6 19 24
7 20 9 14 5
1 22 17 12 3
16 11 2 23 18
21 8 25 4 13
10 15 6 19 24
7 20 9 14 5
1 16 21 12 3
22 11 2 15 20
17 8 13 4 25
10 23 6 19 14
7 18 9 24 5
1 22 11 16 3
12 17 2 21 10
25 8 23 4 15
18 13 6 9 20
7 24 19 14 5
1 22 11 16 3
12 17 2 21 10
23 8 25 4 15
18 13 6 9 20
7 24 19 14 5
1 24 11 16 3
12 17 2 25 10
23 8 21 4 15
18 13 6 9 20
7 22 19 14 5
1 22 11 16 3
12 17 2 23 10
21 8 19 4 15
18 13 6 9 24
7 20 25 14 5
1 20 11 16 3
12 25 2 21 10
19 8 17 4 15
24 13 6 9 22
7 18 23 14 5
1 18 11 24 3
12 23 2 19 10
17 8 15 4 25
22 13 6 9 20
7 16 21 14 5
1 16 11 22 3
12 21 2 17 10
15 8 13 4 23
20 25 6 9 18
7 14 19 24 5
1 14 25 20 3
24 19 2 15 10
13 8 11 4 21
18 23 6 9 16
7 12 17 22 5
1 24 13 18 3
14 19 2 23 12
25 8 11 4 17
20 15 6 9 22
7 10 21 16 5
1 12 15 20 3
16 21 2 25 14
11 8 13 4 19
22 17 6 9 24
7 10 23 18 5
1 12 17 22 3
18 23 2 13 16
11 8 15 4 21
24 19 6 9 14
7 10 25 20 5
1 12 19 24 3
20 25 2 13 18
11 8 17 4 23
16 21 6 9 14
7 10 15 22 5
1 12 23 18 3
24 17 2 13 22
11 8 21 4 19
16 25 6 9 14
7 10 15 20 5
1 12 25 18 3
22 17 2 13 24
11 8 23 4 19
16 21 6 9 14
7 10 15 20 5
1 12 23 18 3
22 17 2 13 24
11 8 25 4 19
16 21 6 9 14
7 10 15 20 5
1 12 21 18 3
22 17 2 13 20
11 8 19 4 25
16 23 6 9 14
7 10 15 24 5
1 12 17 22 3
18 23 2 9 16
13 8 11 4 21
24 19 6 15 10
7 14 25 20 5
1 14 19 24 3
20 25 2 9 18
15 8 13 4 23
12 21 6 17 10
7 16 11 22 5
1 18 23 14 3
24 13 2 9 22
19 8 17 4 15
12 25 6 21 10
7 20 11 16 5
1 20 25 14 3
18 13 2 9 24
21 8 19 4 15
12 17 6 23 10
7 22 11 16 5
1 22 19 14 3
18 13 2 9 20
23 8 21 4 15
12 17 6 25 10
7 24 11 16 5
1 24 19 14 3
18 13 2 9 20
25 8 23 4 15
12 17 6 21 10
7 22 11 16 5
1 24 19 14 3
18 13 2 9 20
23 8 25 4 15
12 17 6 21 10
7 22 11 16 5
1 16 21 14 3
22 13 2 9 20
17 8 15 4 25
12 23 6 19 10
7 18 11 24 5
1 10 21 16 3
20 15 2 9 22
25 8 11 4 17
14 19 6 23 12
7 24 13 18 5
1 10 15 20 3
16 21 2 9 14
11 8 25 4 19
22 17 6 13 24
7 12 23 18 5
1 10 15 20 3
16 21 2 9 14
11 8 23 4 19
22 17 6 13 24
7 12 25 18 5
1 10 15 20 3
16 25 2 9 14
11 8 21 4 19
24 17 6 13 22
7 12 23 18 5
1 10 15 24 3
16 23 2 9 14
11 8 19 4 25
22 17 6 13 20
7 12 21 18 5
1 10 15 22 3
16 21 2 9 14
11 8 17 4 23
20 25 6 13 18
7 12 19 24 5
1 10 25 20 3
24 19 2 9 14
11 8 15 4 21
18 23 6 13 16
7 12 17 22 5
1 10 23 18 3
22 17 2 9 24
11 8 13 4 19
16 21 6 25 14
7 12 15 20 5
1 22 9 16 3
12 17 2 21 10
23 8 11 4 15
18 13 6 25 20
7 24 19 14 5
1 24 9 18 3
14 19 2 23 10
25 8 13 4 17
20 15 6 11 22
7 12 21 16 5
1 14 9 20 3
16 21 2 25 10
13 8 15 4 19
22 17 6 11 24
7 12 23 18 5
1 14 9 22 3
18 23 2 15 10
13 8 17 4 21
24 19 6 11 16
7 12 25 20 5
1 14 9 24 3
20 25 2 15 10
13 8 19 4 23
18 21 6 11 16
7 12 17 22 5
1 14 9 20 3
24 19 2 15 10
13 8 23 4 21
18 25 6 11 16
7 12 17 22 5
1 14 9 20 3
24 19 2 15 10
13 8 25 4 21
18 23 6 11 16
7 12 17 22 5
1 14 9 20 3
22 19 2 15 10
13 8 21 4 25
18 23 6 11 16
7 12 17 24 5
1 20 9 14 3
10 15 2 19 22
25 8 21 4 13
16 11 6 23 18
7 24 17 12 5
1 20 9 14 3
10 15 2 19 24
21 8 25 4 13
16 11 6 23 18
7 22 17 12 5
1 20 9 14 3
10 15 2 19 24
21 8 23 4 13
16 11 6 25 18
7 22 17 12 5
1 24 9 14 3
10 15 2 25 20
23 8 19 4 13
16 11 6 21 18
7 22 17 12 5
1 22 9 14 3
10 15 2 23 18
21 8 17 4 13
16 11 6 19 24
7 20 25 12 5
1 20 9 14 3
10 25 2 21 16
19 8 15 4 13
24 11 6 17 22
7 18 23 12 5
1 18 9 24 3
10 23 2 19 14
17 8 13 4 25
22 11 6 15 20
7 16 21 12 5
1 16 9 22 3
10 21 2 17 12
15 8 11 4 23
20 25 6 13 18
7 14 19 24 5
1 18 5 12 3
8 13 2 17 6
19 22 7 4 11
14 9 24 21 16
23 20 15 10 25
1 10 5 16 3
12 17 2 21 6
9 22 11 4 15
18 13 24 7 20
23 8 19 14 25
1 10 5 18 3
14 19 2 11 6
9 22 13 4 17
20 15 24 7 12
23 8 21 16 25
1 16 5 10 3
6 11 2 15 20
17 22 19 4 9
12 7 24 21 14
23 18 13 8 25
1 20 5 10 3
6 11 2 21 16
19 22 15 4 9
12 7 24 17 14
23 18 13 8 25
1 18 5 10 3
6 11 2 19 14
17 22 13 4 9
12 7 24 15 20
23 16 21 8 25
1 16 21 6 3
10 5 2 15 20
17 22 11 4 7
12 9 24 19 14
23 18 13 8 25
1 18 11 6 3
10 5 2 17 12
19 22 13 4 7
14 9 24 21 16
23 20 15 8 25
1 16 11 6 3
10 5 2 21 12
15 22 17 4 7
18 9 24 13 20
23 14 19 8 25
1 16 11 6 3
10 5 2 17 12
15 22 19 4 7
20 9 24 13 18
23 14 21 8 25
1 10 21 16 3
20 5 2 9 14
11 22 15 4 17
6 19 24 13 8
23 12 7 18 25
1 10 19 14 3
18 5 2 9 20
11 22 13 4 15
6 17 24 21 8
23 12 7 16 25
1 20 15 10 3
14 5 2 21 16
19 22 9 4 11
6 13 24 17 8
23 18 7 12 25
1 18 13 8 3
12 5 2 19 14
17 22 7 4 9
6 11 24 15 20
23 16 21 10 25
1 14 21 8 3
20 9 2 13 18
15 22 19 4 7
10 5 24 17 12
23 16 11 6 25
1 14 19 8 3
18 9 2 13 20
15 22 17 4 7
10 5 24 21 12
23 16 11 6 25
1 20 15 8 3
14 9 2 21 16
19 22 13 4 7
10 5 24 17 12
23 18 11 6 25
1 18 13 8 3
12 9 2 19 14
17 22 11 4 7
10 5 24 15 20
23 16 21 6 25
1 16 21 10 3
6 11 2 15 20
17 22 7 4 9
12 5 24 19 14
23 18 13 8 25
1 18 7 12 3
6 13 2 17 8
19 22 9 4 11
14 5 24 21 16
23 20 15 10 25
1 12 7 16 3
6 17 2 21 8
11 22 13 4 15
18 5 24 9 20
23 10 19 14 25
1 12 7 18 3
6 19 2 13 8
11 22 15 4 17
20 5 24 9 14
23 10 21 16 25
1 8 21 16 3
20 15 2 7 12
9 22 13 4 17
14 19 24 11 6
23 10 5 18 25
1 8 19 14 3
18 13 2 7 20
9 22 11 4 15
12 17 24 21 6
23 10 5 16 25
1 20 15 10 3
14 9 2 21 16
19 22 7 4 11
8 13 24 17 6
23 18 5 12 25
1 16 21 8 3
12 7 2 15 20
17 22 13 4 9
6 11 24 19 14
23 18 5 10 25
1 18 13 8 3
12 7 2 17 14
19 22 15 4 9
6 11 24 21 16
23 20 5 10 25
1 18 13 8 3
12 7 2 21 14
17 22 19 4 9
6 11 24 15 20
23 16 5 10 25
1 18 7 12 25
8 13 2 19 6
3 20 17 24 11
14 9 22 5 16
21 4 15 10 23
1 16 7 12 25
8 13 2 17 6
3 20 15 24 11
14 9 22 5 18
21 4 19 10 23
1 8 19 14 25
18 13 2 9 6
3 20 7 24 15
12 17 22 5 10
21 4 11 16 23
1 6 17 12 25
16 11 2 7 18
3 20 5 24 13
10 15 22 19 8
21 4 9 14 23
1 4 9 14 25
10 15 2 19 8
3 20 5 24 13
16 11 22 7 18
21 6 17 12 23
1 4 11 16 25
12 17 2 5 10
3 20 7 24 15
18 13 22 9 6
21 8 19 14 23
1 4 19 10 25
14 9 2 5 18
3 20 15 24 11
8 13 22 17 6
21 16 7 12 23
1 4 15 10 25
14 9 2 5 16
3 20 17 24 11
8 13 22 19 6
21 18 7 12 23
1 12 19 6 25
18 7 2 11 16
13 20 17 24 5
8 3 22 15 10
21 14 9 4 23
1 12 17 6 25
16 7 2 11 18
13 20 15 24 5
8 3 22 19 10
21 14 9 4 23
1 18 13 6 25
12 7 2 19 14
17 20 11 24 5
8 3 22 15 10
21 16 9 4 23
1 16 11 6 25
10 7 2 17 12
15 20 9 24 5
8 3 22 13 18
21 14 19 4 23
1 14 19 8 25
4 9 2 13 18
15 20 5 24 7
10 3 22 17 12
21 16 11 6 23
1 16 5 10 25
4 11 2 15 6
17 20 7 24 9
12 3 22 19 14
21 18 13 8 23
1 10 5 14 25
4 15 2 19 6
9 20 11 24 13
16 3 22 7 18
21 8 17 12 23
1 10 5 16 25
4 17 2 11 6
9 20 13 24 15
18 3 22 7 12
21 8 19 14 23
时间复杂度:O(8N * N) 辅助空间: O(1)
版权属于:月萌API www.moonapi.com,转载请注明出处