2
public int minHeightShelves(int[][] books, int shelfWidth) {3
int memo[] = new int[books.length];4
return recur(books, shelfWidth, 0, memo);7
private int recur(int[][] books, int shelfWidth, int index, int[] memo) {9
if (index == books.length) {13
if (memo[index] > 0) {16
int ans = Integer.MAX_VALUE;20
for (int i = index; i < books.length; i++) {23
if (width > shelfWidth) {26
height = Math.max(height, books[i][1]);27
ans = Math.min(ans, height + recur(books, shelfWidth, i + 1, memo));29
return memo[index] = ans;