public long maxPoints(int[][] points) {
    int m = points.length;
    int n = points[0].length;
    long INF = -0x3f3f3f3f;
    long[][] dp = new long[m][n];
    for (int j = 0; j < n; j++) {
        dp[0][j] = points[0][j];
    }
    for (int i = 1; i < m; i++) {
        long max = INF;
        for (int j = 0; j < n; j++) {
            max = Math.max(max - 1, dp[i-1][j]);
            dp[i][j] = points[i][j] + max;
        }
        max = INF;
        for (int j = n-1; j >= 0; j--) {
            max = Math.max(max - 1, dp[i-1][j]);
            dp[i][j] = Math.max(dp[i][j], max + points[i][j]);
        }
    }

    return Arrays.stream(dp[m - 1]).max().getAsLong();
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.