Question: ( Java / C / C + + / py ) Bessie and Elsie have discovered a row of N cakes even ) cakes, with

(Java/C/C++/py)Bessie and Elsie have discovered a row of N cakes even) cakes, with sizes a1,a2,dots,aN in that order (1ai109).
Each cow wants to eat as much as possible. However, being very civilized cows, they decided to play a game to split it! The game proceeds with both cows alternating turns. Each turn consists of one of the following:
Bessie chooses two adjacent cakes and stacks them, creating a new cake with the sum of the sizes.
Elsie chooses either the leftmost or rightmost cake and puts it in her stash.
When only one cake remains, Bessie eats it, and Elsie eats all cakes in her stash. If both cows play optimally to maximize the amount of cake they eat and Bessie plays first, how much cake will each cow eat?
INPUT FORMAT (input arrives from the terminal / stdin):
Each input consists of
( Java / C / C + + / py ) Bessie and Elsie have

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!