From 6d2b982d60424f9950080fc2c222af675c81043b Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Tue, 27 Sep 2022 21:07:31 +0800 Subject: [PATCH] 518D - Ilya and Escalator https://codeforces.com/contest/518/submission/173706602 --- Codeforces/518/D/D.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Codeforces/518/D/D.cpp diff --git a/Codeforces/518/D/D.cpp b/Codeforces/518/D/D.cpp new file mode 100644 index 00000000..3f51cadc --- /dev/null +++ b/Codeforces/518/D/D.cpp @@ -0,0 +1,37 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 2005; + +int n, t; +double p, f[N][N], ans; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> p >> t; + + f[0][0] = 1; + for (int i = 1; i <= t; i++) { + f[i][0] = (1.0 - p) * f[i - 1][0]; + + for (int j = 1; j < n; j++) { + f[i][j] = p * f[i - 1][j - 1] + (1.0 - p) * f[i - 1][j]; + } + + f[i][n] = f[i - 1][n] + p * f[i - 1][n - 1]; + } + + for (int i = 1; i <= n; i++) { + ans += f[t][i] * i; + } + + cout << std::fixed << std::setprecision(6) << ans << endl; + + return 0; +}