package leetcode;

/**
 * https://leetcode.com/problems/filling-bookcase-shelves/
 */
public class Problem1105 {
    public int minHeightShelves(int[][] books, int shelf_width) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1105 prob = new Problem1105();
        System.out.println(prob.minHeightShelves(new int[][]{
            {1, 1}, {2, 3}, {2, 3}, {1, 1}, {1, 1}, {1, 1}, {1, 2}
        }, 4)); // 6
    }
}

@@ -184,281 +184,1517 @@
     
-// TODO%0A        return 0;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem1105 prob = new Problem1105();%0A        System.out.println(prob.minHeightShelves(new int%5B%5D%5B%5D%7B%0A            %7B1, 1%7D, %7B2, 3%7D, %7B2, 3%7D, %7B1, 1%7D, %7B1, 1%7D, %7B1, 1%7D, %7B1, 2%7D%0A        %7D, 4)); // 6
+return minHeightShelves(books, shelf_width, 0, 0, 0);%0A    %7D%0A%0A    private static int minHeightShelves(int%5B%5D%5B%5D books, int shelfWidth,%0A                                        int totalWidth, int maxHeight, int index) %7B%0A        if (index == books.length) %7B%0A            return maxHeight;%0A        %7D%0A        int width = books%5Bindex%5D%5B0%5D;%0A        int height = books%5Bindex%5D%5B1%5D;%0A        if (totalWidth + width %3C= shelfWidth) %7B%0A            int a = minHeightShelves(books, shelfWidth, totalWidth + width,%0A                Math.max(maxHeight, height), index + 1);%0A            int b = minHeightShelves(books, shelfWidth, width, height, index + 1) + maxHeight;%0A            return Math.min(a, b);%0A        %7D%0A        return minHeightShelves(books, shelfWidth, width, height, index + 1) + maxHeight;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem1105 prob = new Problem1105();%0A        System.out.println(prob.minHeightShelves(new int%5B%5D%5B%5D%7B%0A            %7B1, 1%7D, %7B2, 3%7D, %7B2, 3%7D, %7B1, 1%7D, %7B1, 1%7D, %7B1, 1%7D, %7B1, 2%7D%0A        %7D, 4)); // 6%0A        System.out.println(prob.minHeightShelves(new int%5B%5D%5B%5D%7B%0A            %7B1, 1%7D, %7B2, 3%7D, %7B2, 3%7D, %7B1, 1%7D, %7B1, 1%7D, %7B1, 1%7D, %7B1, 2%7D%0A        %7D, 8)); // 4%0A        System.out.println(prob.minHeightShelves(new int%5B%5D%5B%5D%7B%0A            %7B1, 1%7D, %7B2, 3%7D, %7B2, 3%7D, %7B1, 1%7D, %7B1, 1%7D, %7B1, 1%7D, %7B1, 2%7D, %7B2, 4%7D, %7B3, 1%7D%0A        %7D, 4)); // 10%0A        System.out.println(prob.minHeightShelves(new int%5B%5D%5B%5D%7B%0A            %7B1, 1%7D, %7B2, 3%7D, %7B2, 3%7D, %7B1, 1%7D, %7B1, 1%7D, %7B1, 1%7D, %7B1, 2%7D, %7B2, 4%7D, %7B3, 1%7D%0A        %7D, 7)); // 7
 %0A   

Update problem 1105