hiho week 264 register

Ended

Participants:100

Verdict:Accepted
Score:100 / 100
Submitted:2019-07-23 17:08:26

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
Author: herongwei
Source: github.com/rongweihe
dp[i][j]ij
i
ii-1j-1dp[i][j]+=dp[i-1][j-1]*p[i]
ii-1jdp[i][j-1]+=dp[i-1][j-1]*(1-p[i])
dp[n][m]
*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
    //freopen("input.txt", "r", stdin);
    int n, m;
    scanf("%d %d", &n, &m);
    double p[n + 1] = {0.0};
    double dp[n+1][n+1] = {0.0};
    for(int i = 1; i <= n; ++i)
        scanf("%lf", &p[i]);
    dp[0][0] = 1.0;
    for(int i = 1; i <= n; ++i)
    {
        for(int j = 1; j <= i; ++j)   //iji
        {
            dp[i][j] += dp[i - 1][j - 1] * p[i];  // head
            dp[i][j - 1] += dp[i - 1][j - 1] * (1 - p[i]); // tail
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX