From ea9baef29c8f2d6e3b6e59ffa7b78c1b45e4757e Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Tue, 15 Nov 2022 17:16:40 +0800 Subject: [PATCH] C - Bath Queue https://codeforces.com/contest/28/submission/181061158 --- Codeforces/28/C/C.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Codeforces/28/C/C.cpp diff --git a/Codeforces/28/C/C.cpp b/Codeforces/28/C/C.cpp new file mode 100644 index 00000000..c410f19d --- /dev/null +++ b/Codeforces/28/C/C.cpp @@ -0,0 +1,59 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 55; + +int n, m, a[N]; +long long c[N][N]; +double f[N][N][N], sum, ans; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + c[0][0] = 1; + for (int i = 1; i < N; ++i) { + c[i][0] = 1; + + for (int j = 1; j <= i; ++j) { + c[i][j] = c[i - 1][j - 1] + c[i - 1][j]; + } + } + + cin >> n >> m; + + for (int i = 1; i <= m; i++) { + cin >> a[i]; + } + + f[0][0][0] = 1; + + for (int i = 1; i <= m; i++) { + for (int j = 0; j <= n; j++) { + for (int k = 0; k <= j; k++) { + for (int l = 0; l <= n - j; l++) { + int p = std::max(static_cast(std::ceil(static_cast(l) / a[i])), k); + + f[i][j + l][p] += f[i - 1][j][k] * c[n - j][l]; + } + } + } + } + + for (int i = 0; i <= n; i++) { + sum += f[m][n][i]; + } + + for (int i = 1; i <= n; i++) { + ans += static_cast(i) * f[m][n][i]; + } + + cout << std::fixed << std::setprecision(20) << ans / sum << endl; + + return 0; +}