Answered step by step
Verified Expert Solution
Question
1 Approved Answer
There is a line of n children waiting for candy. You have an infinite sequence of pieces of candy to hand out. Your candy sequence
There is a line of n children waiting for candy. You have an infinite sequence of pieces of candy to hand out. Your candy sequence consists of two alternating types, beginning with chocolate. E.g.: chocolate, peppermint, chocolate, peppermint, chocolate, peppermint, etc. The candy must be handed out in this alternating order, starting with chocolate. Each child i will get ci units of happiness if she gets a piece of chocolate and pi units of happiness if she gets a piece of peppermint. These values may be different from child to child, and may be negative. You proceed down the line of children, and as you pass each child, you decide whether to give that child the next piece of candy or to skip her. Once you pass a child, you cannot return to that child. Each child gets only 0 or 1 pieces of candy. Design an efficient algorithm to determine which children to give candy to so that the total happiness is maximized
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started