Caterer problem | Algorithms Notes
Let r[i] be the demand of clean napkins in the i-th day, i = 1 ~ n. In the end of day, the caterer must clean all dirty napkins. The caterer can send dirty napkins to a fast laundry with a cost c for each napkin and these napkin will become clean in the next day. Or, the caterer can send dirty napkins to a slow laundry with a cost d for each napkin and these napkins will become clean in three days. The caterer can purchase S clean napkins before the first day with a cost a for each clean napkin. Design an algorithm to find a purchase/laundry plan with the minimum cost subject to the demand.
Solution:
This problem can be solved by using minimum cost flow. Here, we use dynamic programming approach.
Let u[i] and v[i] be the number of napkins sent to a fast laundry and a slow laundry on the i-th day, respectively. The problems is to pick S, u, and v, such that aS + c + d is minimized. It is obvious that u[n] = 0 and v[n] = r[n]. Thus, we objective function becomes aS + +dr[n]. Let K = . The objective function in fact becomes K + aS – (c – d). Intuitively, when S is fixed, our goal is to maximize the number of napkins sent to slow laundry.
Read full article from Caterer problem | Algorithms Notes
Let r[i] be the demand of clean napkins in the i-th day, i = 1 ~ n. In the end of day, the caterer must clean all dirty napkins. The caterer can send dirty napkins to a fast laundry with a cost c for each napkin and these napkin will become clean in the next day. Or, the caterer can send dirty napkins to a slow laundry with a cost d for each napkin and these napkins will become clean in three days. The caterer can purchase S clean napkins before the first day with a cost a for each clean napkin. Design an algorithm to find a purchase/laundry plan with the minimum cost subject to the demand.
Solution:
This problem can be solved by using minimum cost flow. Here, we use dynamic programming approach.
Let u[i] and v[i] be the number of napkins sent to a fast laundry and a slow laundry on the i-th day, respectively. The problems is to pick S, u, and v, such that aS + c + d is minimized. It is obvious that u[n] = 0 and v[n] = r[n]. Thus, we objective function becomes aS + +dr[n]. Let K = . The objective function in fact becomes K + aS – (c – d). Intuitively, when S is fixed, our goal is to maximize the number of napkins sent to slow laundry.
Read full article from Caterer problem | Algorithms Notes