1. Title Description: Click to open the link
2. Problem solving ideas: The problem of using the probability DP solution. According to test instructions description, we can define D (i,j) to indicate the probability of the first I problem doing a J-channel. Then, according to the full probability formula, we can get the following recursive type:
D (i,j) =d (i-1,j) * (1-p[i]) +d (i-1,j-1) *p[i] (0≤j≤i)
Where P[i] indicates the probability of doing the right on the first question. This way, after getting all the D values, Ans=sum{d (i,j) |k≤j≤n}
3. Code:
#define _crt_secure_no_warnings #include <iostream> #include <algorithm> #include <string> #include <sstream> #include <set> #include <vector> #include <stack> #include <map> #include < queue> #include <deque> #include <cstdlib> #include <cstdio> #include <cstring> #include < cmath> #include <ctime> #include <functional>using namespace std; #define N 1000+10double p[n];d ouble D[n] [N];int N, K;int Main () {//freopen ("T.txt", "R", stdin), int t;scanf ("%d", &t), while (t--) {scanf ("%d%d", &n, & k); memset (p, 0, sizeof (p)); memset (d, 0, sizeof (d)); for (int i = 1; I <= n; i++) scanf ("%lf", &p[i]);d [0][0] = 1.0;fo R (int i = 1; I <= n; i++) for (int j = 0; J <= I; j + +)//Note that J must start from 0 {d[i][j] = d[i-1][j] * (1-p[i)); if (j) d[i][ J] + = d[i-1][j-1] * p[i];} Double ans = 0.0;for (int j = k; J <= N; j + +) ans + = D[n][j];p rintf ("%.4lf\n", ans);} return 0;}
Acmer, go brush the questions, XDU1020.