Skip to content

Commit 3411d5d

Browse files
update 1105
1 parent 58ae826 commit 3411d5d

File tree

1 file changed

+10
-1
lines changed
  • src/main/java/com/fishercoder/solutions/secondthousand

1 file changed

+10
-1
lines changed

src/main/java/com/fishercoder/solutions/secondthousand/_1105.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33
public class _1105 {
44
public static class Solution1 {
55
/**
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].
716
*/
817
public int minHeightShelves(int[][] books, int shelfWidth) {
918
//dp[i] means the minimum shelf height after placing all books up to and excluding book i

0 commit comments

Comments
 (0)