Speedrun
Time limit8sMemory limit512 MB
Given per-road win probabilities, choose checkpoints to save at so the expected time to reach checkpoint n is minimized.
- Level
Medium7 of 10
- Topics
- Probability, Dynamic programming
- Solved
- No attempts yet
Problem
Infinite Chronicle -Princess Castle- is a simple role playing game. It has checkpoints numbered through , and for each there is exactly one one way road running from checkpoint to checkpoint . The game starts at checkpoint and ends at checkpoint . Monsters appear on the roads and the hero fights them. You can save your progress at any checkpoint, and if you lose a battle you can restart the game from the checkpoint where you saved last. When the game starts, progress is saved at checkpoint automatically and that save takes no time.
Rabbit Hanako likes this game and now wants to speedrun it. She is an expert player, but random factors keep her from winning every battle. For each she estimated the probability of winning all the battles on the road from checkpoint to checkpoint . Every time she sets out from checkpoint , exactly one minute later she is at checkpoint with probability , and back at the checkpoint of her last save with probability .
Saving at a checkpoint also takes one minute, so passing a checkpoint without saving is sometimes faster. Compute the minimum expected time needed to finish the game.
Input
The input holds several datasets, at most 50 of them. Each dataset has two lines. The first line has one integer (), the number of roads. The second line has numbers (), the winning probabilities, each written with exactly two digits after the decimal point. The last line of the input holds a single zero and is not a dataset.
Output
For each dataset print the minimum expected time in minutes on its own line, with exactly six digits after the decimal point.