概率DP初见之2020牛客寒假算法基础集训营第二场C题 算概率

虽然给出的每个题目的概率是在模数意义下,但是一样算,至于为什么原因就是就是这样。。。。哈哈哈

#include <iostream>
#include <malloc.h>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long LL;
const int maxn = 2000 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
LL p[maxn];
LL dp[maxn][maxn];
int main()
{
#ifdef ONLINE_JUDGE
#else
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> p[i];
    dp[0][0] = 1;
    // 1一个题不做 做错一个的概率 是 0
    // 很不抽象
    for (int i = 1; i <= n; i++)
    {
        dp[i][0] = dp[i - 1][0] * (mod + 1 - p[i]) % mod;
        // 当前题目也没做对的概率
        for (int j = 1; j <= i; j++)
        {
            dp[i][j] = (dp[i - 1][j] * (mod + 1 - p[i]) + dp[i - 1][j - 1] * p[i]) % mod;
            // 前i个题做对j个题目的概率是前i-1个题目做对j题的概率乘第i个题目不对的概率+前i-1个题做对j-1个的概率乘第i个题目做对的概率
        }
    }
    for (int i = 0; i <= n; i++)
        cout << dp[n][i] << " ";
    return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值