深搜+dp即可。 private int[][] dirs=new int[][]{{-1,0},{1,0},{0,-1},{0,1}}; private int m,n; public int solve (int[][] matrix) { // write code here if(matrix.length==0||matrix[0].length==0) return 0; m=matrix.length; n=matrix[0].length; int res=0; ...