static void Main() { StreamReader reader = new StreamReader(@"..\..\date.in"); int x, y, xdest, ydest; int[,] a; #region read string[] tokens = reader.ReadLine().Split(' '); x = int.Parse(tokens[0]); y = int.Parse(tokens[1]); tokens = reader.ReadLine().Split(' '); xdest = int.Parse(tokens[0]); ydest = int.Parse(tokens[1]); CitireMatrice(out a, reader); n = a.GetLength(0); m = a.GetLength(1); #endregion //back pozitie[] st = new pozitie[n * m]; int k = 0; bool[,] b = new bool[n, m]; st[0].lin = x; st[0].col = y; b[x, y] = true; Afisare(a); bk(a, b, st, xdest, ydest, k, st[0]); return; }
static void bk(int[,] a, bool[,] b, pozitie[] st, int lindest, int coldest, int k, pozitie reper) { if (st[k].lin == lindest && st[k].col == coldest) { for (int i = 0; i <= k; i++) { Console.WriteLine(st[i] + "\t"); } Console.WriteLine("=============="); Console.ReadKey(); } else { for (int i = 0; i < dx.Length; i++) { pozitie nou; nou.lin = reper.lin + dx[i]; nou.col = reper.col + dy[i]; if (nou.lin >= 0 && nou.col >= 0 && nou.lin < n && nou.col < m && a[nou.lin, nou.col] != 1 && !b[nou.lin, nou.col]) { st[k + 1] = nou; b[nou.lin, nou.col] = true; bk(a, b, st, lindest, coldest, k + 1, nou); b[nou.lin, nou.col] = false; } } } }