using System; namespace Csharp { class Program { static int N = 0; static int[,] Bamboo = new int[502, 502]; static int[,] Memo = new int[502, 502]; static void Main(string[] args) { N = Convert.ToInt32(Console.ReadLine()); for (int r = 1; r <= N; r++) { var inputs = Console.ReadLine().Split(); for (int c = 0; c < N; c++) Bamboo[r, c + 1] = Convert.ToInt32(inputs[c]); } int ans = 0; for (int r = 1; r <= N; r++) { for (int c = 1; c <= N; c++) ans = Math.Max(ans, Search(r, c) + 1); } Console.Write(ans); } static int Search(int r, int c) { if (0 != Memo[r, c]) return Memo[r, c]; if (Bamboo[r, c] < Bamboo[r - 1, c]) Memo[r, c] = Math.Max(Memo[r, c], Search(r - 1, c) + 1); if (Bamboo[r, c] < Bamboo[r + 1, c]) Memo[r, c] = Math.Max(Memo[r, c], Search(r + 1, c) + 1); if (Bamboo[r, c] < Bamboo[r, c - 1]) Memo[r, c] = Math.Max(Memo[r, c], Search(r, c - 1) + 1); if (Bamboo[r, c] < Bamboo[r, c + 1]) Memo[r, c] = Math.Max(Memo[r, c], Search(r, c + 1) + 1); return Memo[r, c]; } } } |