[ACM] hdu 4418 Time travel (Gaussian deyuan expectation), hdu4418
Time travel
Problem Description
Agent K is one of the greatest agents in a secret organization called Men in Black. once he needs to finish a mission by traveling through time with the Time machine. the Time machine can take agent K to some point (0 to n-1) on the timeline and when he gets to the end of the time line he will come back (For example, there are 4 time points, agent K will go in this way 0, 1, 2, 3, 2, 1, 0, 1, 2, 3, 2, 1,...). But when agent K gets into the Time machine he finds it has broken, which make the Time machine can't stop (Damn it !). Fortunately, the time machine may get recovery and stop for a few minutes when agent K arrives at a time point, if the time point he just arrive is his destination, he'll go and finish his mission, or the Time machine will break again. the Time machine has probability Pk % to recover after passing k time points and k can be no more than M. we guarantee the sum of Pk is 100 (Sum (Pk) (1 <= k <= M) = 100 ). now we know agent K will appear at the point X (D is the direction of the Time machine: 0 represents going from the start of the timeline to the end, on the contrary 1 represents going from the end. if x is the start or the end point of the time line D will be-1. agent K want to know the expectation of the amount of the time point he need to pass before he arrive at the point Y to finish his mission.
If finishing his mission is impossible output "Impossible! "(No quotes) instead.
InputThere is an integer T (T <= 20) indicating the cases you have to solve. the first line of each test case are five integers N, M, Y, X. D (0 <N, M <= 100, 0 <= X, Y <100 ). the following M non-negative integers represent Pk in percentile.
OutputFor each possible scenario, output a floating number with 2 digits after decimal point
If finishing his mission is impossible output one line "Impossible! "
(No quotes) instead.
Sample Input
24 2 0 1 050 504 1 0 2 1100
Sample Output
8.142.00
Source2012 ACM/ICPC Asia Regional Hangzhou Online solution: