rishabh1322's blog

By rishabh1322, history, 2 years ago, In English

Can anyone tell me how to approach this problem ....

Suppose there are given N person each having exactly one candy at initial. Each person gives candy to another person with a factor which decides a cost for buying that candy by another person. You have to maximize candy for a given person with minimum cost. We have to maximize candies for a given person in such a way that the no. of candies for that person is maximum by at least 1 candy from all other persons.

Example:- Suppose there are 5 persons and you have to maximize candies for 1 person then

Candy given from person1 to person2 with cost for buying that is:

Person1 person2 Cost 1 2 12 2 5 28 3 4 18 4 5 42 5 3 18

For the optimum solution, Person 1 can buy candy from person 2 with cost 12 and person 5 with cost 18. So he has 2 candies which are maximum for 5 persons.

Thanks...

Read more »

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it