I - Coins
Time Limit: 2 sec / Memory Limit: 1024 MB
Score : 100100 points
Let NN be a positive odd number.
There are NN coins, numbered 1,2,…,N1,2,…,N. For each ii (1≤i≤N1≤i≤N), when Coin ii is tossed, it comes up heads with probability pipi and tails with probability 1−pi1−pi.
Taro has tossed all the NN coins. Find the probability of having more heads than tails.
NN is an odd number.
1≤N≤29991≤N≤2999
pipi is a real number and has two decimal places.
0<pi<10<pi<1
Input is given from Standard Input in the following format:
Print the probability of having more heads than tails. The output is considered correct when the absolute error is not greater than 10−910−9.
Copy
The probability of each case where we have more heads than tails is as follows:
The probability of having (Coin1,Coin2,Coin3)=(Head,Head,Head)(Coin1,Coin2,Coin3)=(Head,Head,Head) is 0.3×0.6×0.8=0.1440.3×0.6×0.8=0.144;
The probability of having (Coin1,Coin2,Coin3)=(Tail,Head,Head)(Coin1,Coin2,Coin3)=(Tail,Head,Head) is 0.7×0.6×0.8=0.3360.7×0.6×0.8=0.336;
The probability of having (Coin1,Coin2,Coin3)=(Head,Tail,Head)(Coin1,Coin2,Coin3)=(Head,Tail,Head) is 0.3×0.4×0.8=0.0960.3×0.4×0.8=0.096;
The probability of having (Coin1,Coin2,Coin3)=(Head,Head,Tail)(Coin1,Coin2,Coin3)=(Head,Head,Tail) is 0.3×0.6×0.2=0.0360.3×0.6×0.2=0.036.
Thus, the probability of having more heads than tails is 0.144+0.336+0.096+0.036=0.6120.144+0.336+0.096+0.036=0.612.
Outputs such as <code>0.500</code>, <code>0.500000001</code> and <code>0.499999999</code> are also considered correct.
double p[maxn];
double dp[3050][3050];
int n;
dp[1][1]=p[1];
dp[1][0]=1.0000000-p[1];
注意處理下邊界情況就好了。
細節見AC代碼: