← Back to topics
Topic

Arhitekta

M
MilosRadic
what idea should be used here???guessing DP
d
demjan0001
ofc dp ! :D

let's see in what positions can be 2 blocks when you are comparing them:
1st on 2nd
2nd on 1st

so you need max of:
1. carrying capacity2 - weight1
2. carrying capacity1 - weight2

so if (1. > 2.) then you will take 1st on 2nd,
else you will take 2nd on 1st !!!

1 >= 2
<=>
carrying capacity1 + weight1 >= carrying capacity2 + weight2

hope I helped with idea ...
M
MilosRadic
ok but how do i chose the block i will put first(on the beggining of the tower)?i need to check for n*n-1 possibilities and then what?
d
demjan0001
if you sort blocks in decreasing order where first element has the max value of ( a[i].weight + a[i].carrying capacity ).
So there is no point to put (i)th block on (i+j)th ... right ?
because
a[i].carrying capacity - a[i+j].weight > a[i+j].carrying capacity - a[i].weight

so let define dp[n], that is best way to built tower with n blocks and to have max carrying capacity of tower possible.
what is carrying capacity of tower ?
if you have tower of n blocks and let these blocks be in b[n] array, then tower carrying capacity is max( a[ b[1] ].carrying capacity - a[ b[2..n] ].weight, a[ b[2] ].carrying capacity - a[ b[3..n] ].weight, ..., a[ b[n] ].carrying capacity )

so you have to try to put i-th block on tower of (1..i) blocks !
M
MilosRadic
ok buts its not max its min???