Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

SOLVE B . A company is planuing to interview 2 n people. Given a 2 - D array costs of size 2 n x 2

SOLVE B. A company is planuing to interview 2n people. Given a 2-D array costs of size 2n x 2 where costs[i][1] is the cost of flying the ith person to city A, and costs[i][2] is the cost of flying the ith person to city B. We want to return the minimum cost to fly every person to a city such that exactly n people arrive in each city.
Example 1 Input: costs =[[10,20],[30,200],[400,50],[30,20]] Output: 110
Explanation: The first person goes to city A for a cost of 10. The second person goes to city A for a cost of 30. The third person goes to city B for a cost of 50. The fourth person goes to city B for a cost of 20. The total
minimum cost is 10+30+50+20=110 to have half the people interviewing in each city. Example 2 Input: costs a)(10 points) Write down a recursive formulation of the minimum cost, minCost(z,y), which is the minimum cost of sending a people to city A and y people to city B where minCost(n, n) is actually the answer to the original problem. In the solution, consider the possibilities when sending (a + y)t person into a city.
minCost(x,y)=[[259,770],[448,54],[926,667],[184,139],[840,118],[577,469]] Output: 1859
Explanation: The first person goes to city A for a cost of 259. The second person goes to city B for a cost of 54. The third person goes to city B for a cost of 667. The fourth person goes to city A for a cost of 184. The fifth person goes to city B for a cost of 118. The sixth person goes to city A for a cost of 577. The total
minimum cost is 259+54+667+184+118+577=1859 to have half the people interviewing in each city.
(
(b)(10 points) Write a dynamic programming algorithm for finding the minimum cost to fly every person to a city, such that exactly n people arrive in each city. Also, give the running time of your algorithm.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions