- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboxStack.py
More file actions
Latest commit
30 lines (22 loc) · 848 Bytes
/
Copy pathboxStack.py
File metadata and controls
30 lines (22 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
classBox:
def__init__(self, length, breadth, height):
self.length=length
self.breadth=breadth
self.height=height
#custom comparition
def__gt__(self,other):
#return (self.length * self.breadth) > (other.length * other.breadth)
returnself.length>other.lengthandself.breadth>other.breadthandself.height>other.height
defsolution(alist):
max_height=-1
ans=[-1]*(len(alist)+1)
foriinrange(0,len(alist)):
ans[i] =alist[i].height
foriinrange(1,len(alist)):
forjinrange(0,i):
ifalist[j] <alist[i] andans[i] < (ans[j] +alist[i].height):
ans[i] =ans[j] +alist[i].height
printans
returnmax(ans)
alist=[Box(1, 7, 4),Box(2, 6, 9), Box(4, 9, 6), Box(10, 12, 8), Box(6, 2, 5), Box(3, 8, 5), Box(5, 7, 7), Box(2, 10, 16), Box(12, 15, 9)]
printsolution(alist)