Pick days to experiment so no two chosen days are within two days of each other, maximizing the sum of visit probabilities.
Medium4Dynamic programmingGreedyNo attempts yetTime limit2sMemory limit512 MBYour friend Susan works in a biology lab. The rules there are strict, and she wants her boss to see her running an experiment. A single day of experiments drains her, so after every day she spends experimenting she needs at least two days off to recover. If she runs an experiment on Monday, the earliest she can run the next one is Thursday of the same week.
From the visit history Susan knows the probabilities P={p1,p2,…,pn} for n days, where pi is the probability that her boss visits the lab on day i. She can experiment on as many days as she likes as long as she rests in between. Choose the schedule that maximizes the sum of the probabilities on the days she experiments, and report that maximum.
The first line contains the number of test cases T. (0<T≤20)
Each test case takes two lines. The first line contains the number of recorded days n. (0<n≤1000) The second line contains n probabilities, the chance that her boss visits on each day from day 1 to day n, separated by single spaces. Each probability is a decimal number between 0 and 1, inclusive.
For each test case, print the maximum total probability on its own line. Round the exact total to one decimal place, rounding a half up, and always print that one decimal digit. No exact total in the test data lands on a rounding boundary.