Acmer, go brush the questions, XDU1020.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.