Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
42111 Gapple 【S】T2 C++ 通过 100 226 MS 19824 KB 1228 2026-06-13 14:32:54

Tests(10/10):


/* f[1][1] = 3/7 * 0.7 f[1][0] = 0 * 1 f[2][1] = 6/7 * 0.49 f[2][0] = 3/7 * 0.7 */ #include <algorithm> #include <iomanip> #include <iostream> #include <vector> using namespace std; using i64 = long long; struct Prob { double sum, prod; double operator()() const { return sum * prod; } bool operator<(Prob other) const { return (*this)() < other(); } friend Prob operator+(Prob lhs, double rhs) { return { lhs.sum + rhs / (1 - rhs), lhs.prod * (1 - rhs) }; } friend Prob operator+(double lhs, Prob rhs) { return { rhs.sum + lhs / (1 - lhs), rhs.prod * (1 - lhs) }; } }; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; vector<double> p(n); for (auto& x : p) cin >> x; sort(p.rbegin(), p.rend()); vector<Prob> f[2]; f[0].resize(n); f[1].resize(n); f[0][0] = { 0, 1 }; f[1][0] = f[0][0] + p[0]; for (int i = 1; i < n; ++i) { f[0][i] = max(f[0][i - 1], f[1][i - 1]); f[1][i] = max(f[0][i - 1] + p[i], f[1][i - 1] + p[i]); } cout << fixed << setprecision(10) << max(f[0][n - 1], f[1][n - 1])() << endl; return 0; }


测评信息: