Please subscribe to the official Codeforces channel in Telegram via the link https://t.me/codeforces_official. ×

### el_magnito's blog

By el_magnito, history, 4 years ago,

I am stuck in the ELEVATOR problem in cses dp section. I tried to find the solution online but couldnt find any reliable source. PROBLEM LINK — https://cses.fi/problemset/task/1653. It would be a great help if someone can explain the idea behind it.

• 0

| Write comment?
 » 4 years ago, # |   +1 See here: Competitive Programmer's Handbook pdf page 103-104
•  » » 4 years ago, # ^ |   0 Thanks a lot.
•  » » » 3 years ago, # ^ |   0 I cant understand what the bit operations are doing. Can you explain them?
•  » » » » 14 months ago, # ^ |   +1 we have the same pfp
 » 3 years ago, # | ← Rev. 4 →   0 I solved in this way I have two fields DP and MovesMoves[Mask] — the minimum number of elevator ridesDP[Mask] — Minimum Weight Sum of People for the last MoveWe know that we have moves in the priority so the transitions werenewDp = (DP[mask ^ (1 << j)] + w[j]) % xnewMoves = (Moves[mask ^ (1 << j)] + (newDp > Dp[mask ^ (1 << j]))It means that if newDp is bigger that x then new Move is added, and we change the Moves and DP, if Moves > newMoves or (newDp < DP and Moves = newMoves)
•  » » 10 months ago, # ^ |   0 Is I cann't done it with recursion + dpI got tle
 » 3 years ago, # |   0 `for (int s = 1; s < (1<
•  » » 3 years ago, # ^ |   0 no option.second=min(option.second,weight[p]) is incorrect, because we are considering last ride. It means (let the current ride be nth ride), --> we have already completed (n — 1)th ride, so we cannot go back to some kth ride which is obviously (1 <= k < n) and update it.
•  » » » 3 years ago, # ^ |   0 can you tell me why for input {2,3,4,5,9} and lift capaicty as 12 the above algorithm prints:-best[31].first as 1 and best[31].second as 11don't you think (best[31].first) which is actually minimum no of rides should print 2, not 1.
•  » » » » 3 years ago, # ^ | ← Rev. 2 →   0 best[mask].first is the number of complete rides, and best[mask].second is the weigth of the current ride.If best[mask].second == 0, thus the minimum number of rides for mask is best[mask].first, else this number is best[mask].first + 1 (+1 because of the incomplete ride)
 » 12 months ago, # |   0 For a mask, for a set bit b, we are checking whether it can fit in the group already formed with least sum, at this time it is possible that for current mask the minimum sum group will not be (weight[b]+dp_sum[remaining]) and we should now change this dp_sum[current_mask] to sum of the group with least sum. Why we are not doing that? For ex: we have 8,6,4 and max_wt=10, and dp_sum[(8,6)] = 6 and rides[{8,6}] = 2 and on checking for weight 4, dp_sum[{8,6}]+4=10, we are actually doing dp_sum[{8,6,4}]=10 but should not we do dp_sum[{8,6,4}] = 8; as from {8}, {6,4} these groups, 8 has minimum sum group.
 » 5 weeks ago, # |   0 Can anyone suggest a good problem similar to this one for practice?
 » 6 days ago, # |   0 .ComplaintFrame { display: inline-block; position: absolute; top: 0; right: -1.4em; } .ComplaintFrame a { text-decoration: none; color: #ff8c00; opacity: 0.5; } .ComplaintFrame a:hover { opacity: 1; } ._ComplaintFrame_popup p, ._ComplaintFrame_popup button { margin-top: 1rem; } ._ComplaintFrame_popup input[type=submit] { padding: 0.25rem 2rem; } ._ComplaintFrame_popup ul { margin-top: 1em !important; margin-bottom: 1em !important; } The idea is to calculate for each subset of people two values: the minimum number of rides needed and the minimum weight of people who ride in the last group.Above is the whole Idea for given problem, but I am not understanding that why we only need to check for last ride?