File tree 1 file changed +10
-1
lines changed
src/main/java/com/fishercoder/solutions/secondthousand
1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 3
3
public class _1105 {
4
4
public static class Solution1 {
5
5
/**
6
- * Bottom up DP.
6
+ * Bottom up DP:
7
+ * 1. we place the books sequentially, for each book, there are only two options:
8
+ * place it on a new level (this will maximize the height of the shelf);
9
+ * or
10
+ * place it on the previous level if its remaining width still fits the current book's width
11
+ * <p>
12
+ * How it's implemented below is:
13
+ * we always place the new book onto a new level to maximize its height,
14
+ * then we try to move previous books onto this new level as long as the width could accommodate,
15
+ * during this process, we minimize the height for dp[i].
7
16
*/
8
17
public int minHeightShelves (int [][] books , int shelfWidth ) {
9
18
//dp[i] means the minimum shelf height after placing all books up to and excluding book i
You can’t perform that action at this time.
0 commit comments