~/ learn/ comp-372/ cards/ Modeling OilKnapsack as a DP
1 of 5

OilKnapsack recurrence + objective (type it)

OilKnapsack recurrence + objective (type it)

Answer

best[0][0] = 0; best[0][b>=1] = -inf best[i][b] = max( best[i-1][b], # skip order i best[i-1][b - q_i] + p_i ) # fill order i, if q_i <= b profit = max over b of ( best[n][b] - s*(P - b) )

Four lines you should be able to reproduce cold for the project write-up: base case, the skip/fill recurrence, and the storage-adjusted objective scanned over every feasible sold-amount b.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/0f68ef17-ec20-42df-8554-d78c2a757f27/flashcard utf-8 LF