using System; using System.IO; using System.Text; namespace Csharp { class Program { static int N = 0; static int[,] Chess = new int[10, 10]; static int Criterion = 0; static int[] Left = new int[21]; static int[] Right = new int[21]; static int[] Ans = new int[2]; static void Main(string[] args) { N = Convert.ToInt32(Console.ReadLine()); for (int i = 0; i < N; i++) { var inputs = Console.ReadLine().Split(); for (int j = 0; j < N; j++) Chess[i, j] = Convert.ToInt32(inputs[j]); } dfs(0, 0, 0); Criterion = 1; dfs(0, 1, 0); Console.Write(Ans[0] + Ans[1]); } static void dfs(int r, int c, int cnt) { Ans[Criterion] = Math.Max(Ans[Criterion], cnt); if (c >= N) c = Criterion ^ (++r % 2); if (r >= N) return; if (IsPromising(r, c)) { Left[r + c] = Right[r - c + N] = 1; dfs(r, c + 2, cnt + 1); Left[r + c] = Right[r - c + N] = 0; } dfs(r, c + 2, cnt); } static bool IsPromising(int r, int c) { return (Chess[r, c] == 1 && Left[r + c] == 0 && Right[r - c + N] == 0); } } } |