[CF518D] Ilya and Escalator - 概率dp

Description

有 N 个人,每秒最前面的人 p 个概率被弹出,否则不动,求 T 秒后队列中的人数期望。

Solution

\(f[i][j]\) 表示过了 i 秒后,有 j 个人上了电梯的概率

#include <bits/stdc++.h>
using namespace std;

#define int long long
const int N = 2005;
double f[N][N];

signed main()
{
    ios::sync_with_stdio(false);

    int n;
    double p;
    int t;

    cin >> n >> p >> t;

    f[0][0] = 1;
    for (int i = 0; i <= t; i++)
        for (int j = 0; j <= n; j++)
        {
            if (j < n)
                f[i + 1][j + 1] += p * f[i][j];
            else
                f[i + 1][j] += p * f[i][j];
            f[i + 1][j] += (1 - p) * f[i][j];
        }

    double ans = 0;
    for (int i = 1; i <= n; i++)
        ans += f[t][i] * i;

    cout << fixed << setprecision(12) << ans;
}

相关文章:

  • 2022-12-23
  • 2021-11-24
  • 2021-10-17
  • 2022-12-23
  • 2022-12-23
  • 2022-03-08
  • 2022-12-23
  • 2021-07-21
猜你喜欢
  • 2021-11-16
  • 2021-06-07
  • 2021-06-30
  • 2021-05-27
  • 2022-02-15
  • 2021-05-22
  • 2022-12-23
相关资源
相似解决方案