The Eastern Reserve Logistics Company operates under the assumption that it need
ID: 3791918 • Letter: T
Question
The Eastern Reserve Logistics Company operates under the assumption that it needs a single vehicle for deliveries over the next n months. The vehicle can be leased at various costs and for various lengths of time: a three-month plan for $a, a four-month plan for $b, and a five-month plan for $c. The company can subscribe to a leasing plan beginning any month. The company has plenty of available parking and, although only one vehicle is required, it can lease additional unused vehicles if it helps with leasing costs. Describe a recursive algorithm that returns the smallest leasing cost. Please provide the answer in pseudocode without using any library functions. This is an algorithm, not a computer program. Thank you.
Explanation / Answer
//main function
main()
n //number of months
a //a plan value
b // b plan value
c // c plan value
aP = a/3; // a plan cost per month
bP = b/4; // b plan cost per month
cP = c/5; // c plan cost per month
leasingCost = smallestLeasingCost(n,aP,bP,cP)
//Recusrsive function
int smallestLeasingCost(int n ,double aP,double bP, double cP)
n // total time in months
static cost <- 0;
if n ==0 then
return cost;
else
month = min(aP,bP,cP) // it will return months in cheap plan
if n > 0 && month ==5
n -= month;
if n < 0 then
n =0
cost = c + smallestLeasingCost(n);
else if n > 0 && month ==4
n -= month;
if n < 0 then
n =0
cost = b + smallestLeasingCost(n);
else if n> 0 && month ==3
n -= month;
if n < 0 then
n =0
cost += a + smallestLeasingCost(n);
return cost;
//function to find min cost plan per month
int min(a,b,c)
if a < b then
if a < c then
return 3;
else
return 5;
else
if b < c then
return 4;
else
return 5;
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.