3
int minHeightShelves(vector<vector<int>> &books, int shelfWidth) {5
vector<vector<int>> cost(n + 1, vector<int>(n + 1));6
for (int i = 1; i <= n; i++) {7
int height = books[i - 1][1];8
int width = books[i - 1][0];10
for (int j = i + 1; j <= n; j++) {11
height = max(height, books[j - 1][1]);12
width += books[j - 1][0];13
if (width <= shelfWidth)19
vector<int> ans(n + 1);21
for (int i = 1; i <= n; i++) {23
for (int j = 1; j <= i; j++) {24
if (cost[j][i] == -1) continue;25
if (ans[j - 1] != INT_MAX) ans[i] = min(ans[i], ans[j - 1] + cost[j][i]);