You have a sideline business buying and selling vintage jukeboxes. You have room
ID: 3600541 • Letter: Y
Question
You have a sideline business buying and selling vintage jukeboxes. You have room to store up to two jukeboxes and feel certain that the following prices will prevail over the next four months:
Each month, you have a choice of one of the following three actions:
Buy: buy one jukebox at the bid price (unless you already have two in storage)
Hold: do nothing (allowable with any number of jukeboxes in storage, including zero)
Sell: sell one jukebox at the ask price (unless you do not have any left in storage).
You have a direct holding cost of $100 for each jukebox in storage at the end of each month (for maintenance and cleaning), and want to maximize your profit from trading jukeboxes over the next four months. Assume that you do not have any jukeboxes currently in storage, and that you ascribe a “salvage” value of $2000 to each jukebox left over after the end of the four months (holding cost at the end of month four still applies to any such jukeboxes).
Manually solve this problem by dynamic programming, showing your work. What is the optimal trading strategy, and what is the resulting profit?
Month 1 2 3 4 Sell (ask) Price $2500 $2800 $2000 $2700 Buy (bid) Price $2600 $2900 $2100 $2800Explanation / Answer
ANSWER::
int getMinSteps ( int n )
{
int dp[n+1] , i;
dp[1] = 0; // trivial case
for( i = 2 ; i < = n ; i ++ )
{
dp[i] = 1 + dp[i-1];
if(i%2==0) dp[i] = min( dp[i] , 1+ dp[i/2] );
if(i%3==0) dp[i] = min( dp[i] , 1+ dp[i/3] );
}
return dp[n];
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.