We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents ed5ceb9 + 42995ca commit 080b638Copy full SHA for 080b638
1105. Filling Bookcase Shelves
@@ -0,0 +1,40 @@
1
+class Solution {
2
+public:
3
+ int n,w;
4
+ vector<vector<int>> a;
5
+ vector<int> dp;
6
+ int ans=INT_MAX;
7
+ int f(int i)
8
+ {
9
+ if (i>=n)
10
+ return 0;
11
+ if(dp[i]!=INT_MAX)
12
+ return dp[i];
13
+ // int a=INT_MAX;
14
+ int cw=0,ch=0;
15
+ for(int j=i;j<n;j++)
16
17
+ if(cw+a[j][0]<=w)
18
19
+ dp[i]=min(dp[i],max(ch,a[j][1])+f(j+1));
20
+ ch=max(ch,a[j][1]);
21
+ cw+=a[j][0];
22
+ }
23
+ else
24
+ break;
25
+
26
27
28
29
30
+ int minHeightShelves(vector<vector<int>>& books, int w) {
31
32
33
+ this->n=books.size();
34
+ this->a=books;
35
+ this->w=w;
36
+ dp.resize(n,INT_MAX);
37
+ return f(0);
38
39
40
+};
0 commit comments