using System; class Example { static int N = 8; static int[] dx = {2, 1,-1,-2,-2,-1, 1, 2}; // ходи коня static int[] dy = {1, 2, 2, 1,-1,-2,-2,-1}; static bool step (int x, int y, int i, int[,] sol) { int k, next_x, next_y; if (i == N * N) return true; for (k = 0; k < 8; k++) { next_x = x + dx[k]; next_y = y + dy[k]; if (next_x >= 0 && next_x < N && next_y >= 0 && next_y < N && sol[next_x,next_y] == -1) { sol[next_x,next_y] = i; if (step(next_x, next_y, i + 1, sol)) return true; else sol[next_x,next_y] = -1; } } return false; } public static void Main() { int[,] sol = new int[N,N]; // розв'язок for (int x = 0; x < N; x++) for (int y = 0; y < N; y++) sol[x,y] = -1; sol[0,0] = 0; if (!step(0, 0, 1, sol)) Console.WriteLine("Розв'язків немає"); else for (int x = 0; x < N; x++) { for (int y = 0; y < N; y++) if (sol[x,y]<10) Console.Write(" {0}",sol[x,y]); else Console.Write( " {0}",sol[x,y]); Console.WriteLine(); } } }