Given per-road win probabilities, choose checkpoints to save at so the expected time to reach checkpoint n is minimized.
Medium7ProbabilityDynamic programmingNo attempts yetTime limit8sMemory limit512 MBInfinite Chronicle -Princess Castle- is a simple role playing game. It has n+1 checkpoints numbered 0 through n, and for each i=1,2,…,n there is exactly one one way road running from checkpoint i−1 to checkpoint i. The game starts at checkpoint 0 and ends at checkpoint n. 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 0 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 i she estimated the probability pi of winning all the battles on the road from checkpoint i−1 to checkpoint i. Every time she sets out from checkpoint i−1, exactly one minute later she is at checkpoint i with probability pi, and back at the checkpoint of her last save with probability 1−pi.
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.
The input holds several datasets, at most 50 of them. Each dataset has two lines. The first line has one integer n (1≤n≤105), the number of roads. The second line has n numbers p1,p2,…,pn (0<pi≤1), 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.
For each dataset print the minimum expected time in minutes on its own line, with exactly six digits after the decimal point.