Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A natural disaster has hit the Pioneer Valley! The paramedics have n injured peo

ID: 3710038 • Letter: A

Question

A natural disaster has hit the Pioneer Valley! The paramedics have n injured people that they need to get to k hospitals. Each person needs to get to a hospital within a half-hour driving time from their current location, so each person i has a set of hospitals they can go to Si ? {1, . . . , k}. At the same time, the paramedics do not want to overload any hospital, so they are not allowed to send more than ?n/k? patients to any single hospital.

Design an algorithm that the paramedics can use to decide whether it is possible to get injured people to the hospital, so that both the locality constraint and the overloading constraint are satisfied.

Your algorithm need not output a assignment of people to hospitals, just whether one exists or not.

Explanation / Answer

ANS:-

Given that,

  A natural disaster has hit the Pioneer Valley! The paramedics have n injured people that they need to get to k hospitals. Each person needs to get to a hospital within a half-hour driving time from their current location.

This is a problem of Dynamic Programming :-

You can define your function assuming the limits c[0], c[1], ... c[m-1] = n/k max as fixed and then writing the recursive formula that returns the number of ways you can distribute n people into k hospitals starting at some index k. With this approach a basic formula is simply

then you need to add memoization (this will be equivalent to a DP approach) and some other optimizations like e.g. that if n > c[k] + c[k+1] + c[k+2] + ... then you know there are no solutions without the need to search (and you can precompute the partial sums).

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote