I made a simple solution in Python to solve the problem but it failed on all large testcases. The precision cannot be an issue because I am multiplying all probabilities by 10^4 and converting them to int.

Here is the link to my solution

http://www.codechef.com/viewsolution/7444346

Please help… I just wasted 2 days thinking my maths was wrong.