Want to try solving this problem? You can submit your code online if you log in or register.
Your backyard has been overrun by adorably tiny hippos, and they are eating the daisies!
You have a line of N daisies, labelled from 1 to N. There are three hippos standing next to different daisies ...and they are already eating them! If you don't act fast, they will eat all the daisies in your garden.
You have enough plywood to build up to three fences. Each fence will be built between two daisies that are next to each other. Hippos cannot go through fences (or over them, or under them, or around them).
Once you have built your fences, the hippos will roam back and forth along the line of daisies, eating all the daisies they can reach without crossing your fences. What is the greatest number of daisies you can save?
Your program should read from the file hippoin.txt.
Your program should write to the file hippoout.txt. Your output file should contain one line with one integer: the greatest number of daisies you can save.
9 2 5 7
3 1 2 3
In the first sample case, as illustrated above, if we put a fence between daisies 2 and 3, between daisies 4 and 5 and between daisies 7 and 8, no hippo will be able to reach daisies 3, 4, 8 or 9. There is no placement of fences that will save more daisies, so 4 is the correct answer.
In the second sample case, no matter where you place the three fences you will not save any daisies, as they are all being eaten.
To evaluate your solution, the judges will run your program against several different input files. All of these files will adhere to the following bounds:
© Australian Mathematics Trust 2001-2023
Page generated: 3 June 2023, 3:18pm AEST