Stack Rotatable Cuboids for Maximum Height. Choose a subset of cuboids and orient each by permuting its three dimensions. A cuboid may sit on another only when its width, length, and height are each no larger than the corresponding dimension below it.
### Problem
Choose a subset of `cuboids` and orient each by permuting its three dimensions. A cuboid may sit on another only when its width, length, and height are each no larger than the corresponding dimension below it. Return the greatest possible sum of the chosen vertical heights.
```cpp
class Solution {
public:
int maxHeight(vector<vector<int>>& cuboids);
};
```
### Examples
**Example 1:**
```text
cuboids = [[1,2,3],[2,3,4]]
Output: 7
Explanation: Orient the smaller cuboid with height 3 on the one with height 4.
```
**Example 2:**
```text
cuboids = [[2,4,6],[6,2,4],[1,1,1]]
Output: 13
Explanation: The first two are equal after rotation; stack both at height 6 with the unit cube above.
```
### Constraints
- `n == cuboids.length`, with `1 <= n <= 100`.
- Every cuboid has three integer dimensions, each in `[1,100]`.
### Clarifying Questions
The source placement rule compares all three dimensions, including height. Equal dimensions are allowed, and each input cuboid is used at most once.
```hint Inspect the structure
After an orientation is chosen, which of the three corresponding dimensions must satisfy the placement rule?
```
### Reasoning checkpoints
- Validate every chosen orientation and all three placement inequalities.
- Prove maximum total height while allowing equal cuboids and using each physical occurrence at most once.
### Optional extensions
Why would a variant comparing only base dimensions require a different orientation analysis?
Overview: Stack Rotatable Cuboids for Maximum Height. Choose a subset of cuboids and orient each by permuting its three dimensions. A cuboid may sit on another only when its width, length, and height are each no larger than the corresponding dimension below it.
Choose a subset of cuboids and orient each by permuting its three dimensions. A cuboid may sit on another only when its width, length, and height are each no larger than the corresponding dimension below it. Return the greatest possible sum of the chosen vertical heights.
class Solution {
public:
int maxHeight(vector<vector<int>>& cuboids);
};
Examples
Example 1:
cuboids = [[1,2,3],[2,3,4]]
Output: 7
Explanation: Orient the smaller cuboid with height 3 on the one with height 4.
Example 2:
cuboids = [[2,4,6],[6,2,4],[1,1,1]]
Output: 13
Explanation: The first two are equal after rotation; stack both at height 6 with the unit cube above.
Constraints
n == cuboids.length
, with
1 <= n <= 100
.
Every cuboid has three integer dimensions, each in
[1,100]
.
Clarifying Questions Guidance
The source placement rule compares all three dimensions, including height. Equal dimensions are allowed, and each input cuboid is used at most once.
Reasoning checkpoints
Validate every chosen orientation and all three placement inequalities.
Prove maximum total height while allowing equal cuboids and using each physical occurrence at most once.
Optional extensions
Why would a variant comparing only base dimensions require a different orientation analysis?