public int maxHeight(int[][] cuboids) {
    int n = cuboids.length;
    for (int i = 0; i < n; i++) {
        Arrays.sort(cuboids[i]);
    }
    Arrays.sort(cuboids,(a,b)->{
        return a[0] == b[0] ? (a[1] == b[1] ? a[2] - b[2] : a[1] - b[1]) : a[0] - b[0];});
    int[] dp = new int[n];
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < i; j++) {
            if (cuboids[i][1] >= cuboids[j][1] && cuboids[i][2] >= cuboids[j][2]) {
                dp[i] = Math.max(dp[i], dp[j]);
            }
        }
        dp[i] = dp[i] + cuboids[i][2];
        ans = Math.max(dp[i], ans);
    }
    return ans;
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.