AtCoder Beginner Contest 382 (E-F)
E
概率期望
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define pii pair<int, int>
#define endl '\n'
#define mkp make_pair
// #define int long long
const int N = 5000+ 10, mod = 998244353;
int n, m;
double f[N][N], g[N];
double a[N], ans = 0;
void solve() {
cin >> n >> m;
f[0][0] = 1;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
f[i][0] = (100 - a[i]) / 100 * f[i - 1][0];
for (int j = 1; j <= n; j++) {
f[i][j] = f[i - 1][j - 1] * a[i] / 100 + f[i - 1][j] * (100 - a[i]) / 100;
}
}
double x = 1 - f[n][0];
for (int i = 1; i <= m; i++) {
g[i] = 1;
for (int j = 1; j < i; j++) {
g[i] += g[max(0, i - j)] * f[n][j];
}
g[i] /= x;
}
printf("%.6lf", g[m]);
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
// cin >> T;
while(T--) solve();
}
F
线段树裸题