Partition n levels into k consecutive groups to minimize the expected total time of a random coin-draw process, and print it to six decimals.
Hard8Dynamic programmingDivide and conquerProbabilityPrefix sumInterviewNo attempts yetTime limit2sMemory limit512 MBAreum plays a computer game with n levels, numbered 1 through n.
The n levels are split into k groups. Each group consists of consecutive levels, every level belongs to exactly one group, and no group is empty.
The game repeats the following process.
The expected time until the game ends depends on how the levels are split. Given n, k and t1,t2,…,tn, write a program that computes the expected time for a split that makes it as small as possible.
The first line contains n and k. (1≤n≤200000, 1≤k≤min(50,n))
The second line contains t1,t2,…,tn. (1≤ti≤100000)
Print the smallest expected time on one line, rounded to six digits after the decimal point. Pad with zeros so that six digits always follow the decimal point.
In the first example, putting level 1 in one group and the remaining levels in the other group is optimal.
In the second example, splitting the levels into two groups of three is optimal.