private static void FindPath(int row, int col, int steps) { if (row + 1 < LargestConnectedArea.MatrixSize && LargestConnectedArea.matrix[row + 1, col]) { LargestConnectedArea.matrix[row + 1, col] = false; LargestConnectedArea.FindPath(row + 1, col, steps + 1); LargestConnectedArea.matrix[row + 1, col] = true; } if (col + 1 < LargestConnectedArea.MatrixSize && LargestConnectedArea.matrix[row, col + 1]) { LargestConnectedArea.matrix[row, col + 1] = false; LargestConnectedArea.FindPath(row, col + 1, steps + 1); LargestConnectedArea.matrix[row, col + 1] = true; } if (row - 1 >= 0 && LargestConnectedArea.matrix[row - 1, col]) { LargestConnectedArea.matrix[row - 1, col] = false; LargestConnectedArea.FindPath(row - 1, col, steps + 1); LargestConnectedArea.matrix[row - 1, col] = true; } if (col - 1 >= 0 && LargestConnectedArea.matrix[row, col - 1]) { LargestConnectedArea.matrix[row, col - 1] = false; LargestConnectedArea.FindPath(row, col - 1, steps + 1); LargestConnectedArea.matrix[row, col - 1] = true; } if (LargestConnectedArea.maxSteps < steps) { LargestConnectedArea.maxSteps = steps; } }
public static void Main() { LargestConnectedArea.FindPath(0, 0, 0); Console.WriteLine(LargestConnectedArea.maxSteps); }