Describe
Little hi has a magical coin. The probability that the positive upward is the pi when the coin is thrown in the first time is known.
Now little hi wants to know what the probability of the right M-positive upward is if the total is thrown n times.
Input
The first line contains two integers of N and M.
The second line contains n real P1, P2, ... Pn.
For 30% of data, 1 <= N <= 20
For 100% data, 1 <= n <=, 0 <= M <= N, 0 <= Pi <= 1
Output
The output line of a real number represents the probability of just m-times positive upward. Note that the end of the line needs to contain a newline character ' \ n '.
The output and standard answer errors are considered correct within 0.001.
Sample input
2 1
0.5 0.5
Sample output
0.500000
DP[I][J] means I cast, J Times face up.
#include <iostream> #include <algorithm> #include <iostream> #include <
Cstdio> #include <cstring> using namespace std;
const int MAXN = 1E3+50;
Double A[MAXN], DP[MAXN][MAXN];
int main () {int n,m;
while (scanf ("%d%d", &n,&m)! = EOF) {for (int i=1;i<=n;i++) scanf ("%lf", a+i);
Dp[0][0] = 1, dp[0][1] = 0;
for (int i=1;i<=n;i++) {dp[i][0] = dp[i-1][0]* (1.0-a[i]);
for (int j=1;j<=i;j++) {Dp[i][j] = dp[i-1][j]* (1.0-a[i]) + dp[i-1][j-1]*a[i];
}} printf ("%lf\n", Dp[n][m]);
} return 0; }