Question

UPS is renting trucks to deliver packages for morning and evening shifts. Each zone of the...

UPS is renting trucks to deliver packages for morning and evening shifts. Each zone of the city needs several trucks and those numbers are calculated and given to the manager by midnight on a daily basis. With this data the manager will then rent enough trucks for the morning shift and reuse them for the afternoon shift. Note that each zone must be completely covered in either shift.

For examples, if the city has 4 zones and their truck requirements, in this order, zone #1 needs 1 truck, zone#2 needs 6 trucks, zone#3 needs 11 trucks and zone#4 needs 5 trucks, the manager could rent 16 trucks to deliver packages in zones #3 (11 trucks) and #4 (5 trucks) in the morning shift and reuse 7 trucks to cover zones #1 (1 truck) and #2 (6 trucks) in the afternoon shift but he would need to leave 9 trucks unused for the afternoon shift. Alternatively, the manager could have rented 12 trucks to cover zones #1 (1 truck) and #3 (11 trucks) in the morning and reuse 11 trucks to deliver packages in zones #2 (6 trucks) and #4 (5 trucks). In this plan, he would only have 1 truck left unused. Note that 12 is also the minimum number of trucks needed.

Find the minimum numbers of trucks for daily delivery. Is there an optimal solution? Use any programming language to solve this problem and write a pseudo-code for the procedure. What is the time complexity?

Homework Answers

Answer #1

#include <iostream>
using namespace std;

int minDiffSubset(int arr[], int i, int n, int sumCalculated, int sumTotal)
{
if (i==n)
return abs((sumTotal-sumCalculated) - sumCalculated);

return min(minDiffSubset(arr, i+1, n, sumCalculated+arr[i], sumTotal),
minDiffSubset(arr, i+1, n, sumCalculated, sumTotal));
}

int main() {
   int n;
   cin>>n;
   int a[n];
   int sum = 0;
   for(int i=0;i<n;i++) {
       cin>>a[i];
       sum+=a[i];
   }

   int minDiff = minDiffSubset(a, 0, n, 0, sum);

   int ans = (sum + minDiff) / 2;

   cout<<ans<<endl;
}

// Time complexy = O(2^N) where N is the number of zones

/*
Pseudo code
a = list of the number of trucks needed to each zone
n = size of a

for i in 0..n:
   sum = sum + a[i]

Now the problem becomes like partitioning a set into two subsets such that the difference of subset sums is minimum
Recursively find the minimum diff of subset sum using this recursive call

minDiff = min(minDiffSubset(arr, i+1, n, sumCalculated+arr[i], sumTotal),
minDiffSubset(arr, i+1, n, sumCalculated, sumTotal))

Once we find the minDiff the answer will be the (sum + minDiff) / 2

*/


/*
Optimization

This could be optimized by using DP to find the partition of a set into two subsets such that the difference of subset sums is minimum


dp[i][j] = dp[i-1][j] || dp[i-1][j-a[i]];
here dp[i][j] denotes whether j sum is possible using a subset of first i elements

Now since you know if a particular sum is possbile or not, you can check for the minimum sum that is possible and which is grater than sum/2.
Here sum is the sum of all the elements of the array or list.

*/

/*
code with dp

#include <iostream>
using namespace std;

int minTrucksRequired(int a[], int n, int sum)
{
bool dp[n+1][sum+1];

for (int i=0;i<=n;i++) {
        dp[i][0] = true;
}

for(int i=0;i<=sum;i++) {
        dp[0][i] = false;
}

dp[0][0] = true;

for (int i=1;i<=n;i++) {
    for (int j=1;j<=sum;j++) {
        dp[i][j] = dp[i-1][j];
        if (j>=a[i-1]) {
            dp[i][j] = dp[i][j] | dp[i-1][j-a[i-1]];
        }

    }
}

for(int i=0;i<=sum;i++) {
      if (dp[n][i]) {
          cout<<i<<endl;
          if (i*2 >= sum )
          {
             return i;
          }
      }
}
return 0;
}

int main() {
   int n;
   cin>>n;
   int a[n];
   int sum = 0;
   for(int i=0;i<n;i++) {
       cin>>a[i];
       sum+=a[i];
   }

   cout<<minTrucksRequired(a, n, sum);
}
*/

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Capital Budgeting Case Scanning: Evaluating a new technology National Courier Company picks up and delivers packages...
Capital Budgeting Case Scanning: Evaluating a new technology National Courier Company picks up and delivers packages across the country and, through its relationships with couriers in other countries, provides international package delivery services. Each afternoon couriers pick up packages. In late afternoon, the packages are returned to the courier's terminal, where they are placed in bins and shipped by air to National Courier Company's hub. In the hub, these bins are emptied. The packages are sorted and put into different...
Background information for the assignment. You are the RN on a morning shift on the respiratory...
Background information for the assignment. You are the RN on a morning shift on the respiratory ward of a large inner-city hospital. At 10:30 AM you receive a patient from the Emergency Department. This is the hand-over you receive. I My name is Catriona and I am the A&E RN who has been caring for Ms Aaliyah Abimbola. Thank you so much for taking this patient so quickly. We’re so busy we haven’t time to do much for her apart...
You are the RN on a morning shift on the respiratory ward of a large inner-city...
You are the RN on a morning shift on the respiratory ward of a large inner-city hospital. At 10:30 AM you receive a patient from the Emergency Department. This is the hand-over you receive. I My name is Catriona and I am the A&E RN who has been caring for Ms Aaliyah Abimbola. Thank you so much for taking this patient so quickly. We’re so busy we haven’t time to do much for her apart from get her ready to...
Ms Aaliyah Abimbola Background information for the assignment. You are the RN on a morning shift...
Ms Aaliyah Abimbola Background information for the assignment. You are the RN on a morning shift on the respiratory ward of a large inner-city hospital. At 10:30 AM you receive a patient from the Emergency Department. This is the hand-over you receive. I My name is Catriona and I am the A&E RN who has been caring for Ms Aaliyah Abimbola. Thank you so much for taking this patient so quickly. We’re so busy we haven’t time to do much...
CASE STUDY Ms Aaliyah Abimbola is a 56-year-old female who emigrated from African 20 years ago....
CASE STUDY Ms Aaliyah Abimbola is a 56-year-old female who emigrated from African 20 years ago. Ms. Abimbola is a single parent with three female children (ages 14, 17, and 18 ) living in the inner-west of Melbourne. You are working on the respiratory ward and have been allocated to Ms. Abimbola who has been admitted with an exacerbation of COPD. Ms. Abimbola presented to A&E via ambulance at 8 AM after experiencing acute shortness of breath while preparing breakfast...
Ms Aaliyah Abimbola; a 56-year old female who emigrated from Africa 20 years ago. Ms Abimbola...
Ms Aaliyah Abimbola; a 56-year old female who emigrated from Africa 20 years ago. Ms Abimbola is a single parent with three female children, ages 14, 17 and 18. You are working on the respiratory ward and have been allocated to Ms Abimbola who has been admitted with exacerbation of COPD. Ms Abimbola presented to A&E via ambulance at 8AM after experiencing acute shortness of breath while preparing breakfast this morning. Based on the information provided in this case study,...
Ms Aaliyah Abimbola; a 56-year old female who emigrated from Africa 20 years ago. Ms Abimbola...
Ms Aaliyah Abimbola; a 56-year old female who emigrated from Africa 20 years ago. Ms Abimbola is a single parent with three female children, ages 14, 17 and 18. You are working on the respiratory ward and have been allocated to Ms Abimbola who has been admitted with exacerbation of COPD. Ms Abimbola presented to A&E via ambulance at 8AM after experiencing acute shortness of breath while preparing breakfast this morning. Background information for the assignment. You are the RN...
Powerpoint slides for COPD with the given case study by using CRC. Ms Aaliyah Abimbola Background...
Powerpoint slides for COPD with the given case study by using CRC. Ms Aaliyah Abimbola Background information for the assignment. You are the RN on a morning shift on the respiratory ward of a large inner-city hospital. At 10:30 AM you receive a patient from the Emergency Department. This is the hand-over you receive. I My name is Catriona and I am the A&E RN who has been caring for Ms Aaliyah Abimbola. Thank you so much for taking this...
Powerpoint slides for COPD with the given case study by using CRC. Ms Aaliyah Abimbola Background...
Powerpoint slides for COPD with the given case study by using CRC. Ms Aaliyah Abimbola Background information for the assignment. You are the RN on a morning shift on the respiratory ward of a large inner-city hospital. At 10:30 AM you receive a patient from the Emergency Department. This is the hand-over you receive. I My name is Catriona and I am the A&E RN who has been caring for Ms Aaliyah Abimbola. Thank you so much for taking this...
Powerpoint slides for COPD with the given case study by using CRC. Ms Aaliyah Abimbola Background...
Powerpoint slides for COPD with the given case study by using CRC. Ms Aaliyah Abimbola Background information for the assignment. You are the RN on a morning shift on the respiratory ward of a large inner-city hospital. At 10:30 AM you receive a patient from the Emergency Department. This is the hand-over you receive. I My name is Catriona and I am the A&E RN who has been caring for Ms Aaliyah Abimbola. Thank you so much for taking this...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT