传送门
令 \(dp[i]\) 表示前 \(i\) 个人中被鲨死的人数的期望
则有两种情况:
// Problem: 抓住仿生泪滴 // Contest: NowCoder // URL: https://ac.nowcoder.com/acm/contest/35753/F // Memory Limit: 262144 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) #include <bits/stdc++.h> using namespace std; typedef long long ll; #define rep(i, a, b) for(int i(a); i <= b; i ++) #define dec(i, a, b) for(int i(a); i >= b; i --) #ifdef LOCAL #include <debugger> #else #define debug(...) 42 #endif template <typename T> inline void chkmax(T &x, T y) { x = max(x, y); } template <typename T> inline void chkmin(T &x, T y) { x = min(x, y); } void solve() { int n; cin >> n; vector<int> a(n); for(int &x: a) cin >> x; vector<double> f(n); for(int i = 1; i < n; i ++ ) { if(a[i]) f[i] = f[i - 1]; else f[i] = f[i - 1] + 1 + (i - f[i - 1]) / (i); } cout << f.back(); } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(6); solve(); return 0; } /* * * ┏┓ ┏┓+ + * ┏┛┻━━━┛┻┓ + + * ┃ ┃ * ┃ ━ ┃ ++ + + + * ████━████+ * ◥██◤ ◥██◤ + * ┃ ┻ ┃ * ┃ ┃ + + * ┗━┓ ┏━┛ * ┃ ┃ + + + +Code is far away from * ┃ ┃ + bug with the animal protecting * ┃ ┗━━━┓ 神兽保佑,代码无bug * ┃ ┣┓ * ┃ ┏┛ * ┗┓┓┏━┳┓┏┛ + + + + * ┃┫┫ ┃┫┫ * ┗┻┛ ┗┻┛+ + + + */