if (points.length == 0) { return0; } long result = 0; int m = points.length; int n = points[0].length; long[][] dp = newlong[m][n]; for (int i = 0; i < n; i++) { dp[0][i] = points[0][i]; result = Math.max(result,dp[0][i]); } for (int i = 1; i < m; i++) { for (int j = 0; j < n; j++) { for (int k = 0; k < n; k++) { long score = points[i][j] + dp[i-1][k] - Math.abs(j-k); dp[i][j] = Math.max(score,dp[i][j]); } result = Math.max(result,dp[i][j]); }