/* 非常值得重新重做的概率题,化连续为离散,分为(2^M +1)个区间,double型的赌注,则用该区间内的int型来代替,反正效果一样(最终得到的概率是相等的) 等到要输出prv[i]时,再去找在dp数组中,该本金对应的是(2^M+1)个区间中的哪个区间 */ #include <cstdio> #include <iostream> #include <algorithm> #include <cstring> #include <iomanip> using namespace std; typedef long long ll; const int MAX_M = 15; int M, X; double P; double dp[2][(1 << MAX_M) + 1]; void solve() { int n = 1 << M; double *prv = dp[0], *nxt = dp[1]; memset(prv, 0, sizeof (double ) * (n + 1)); prv[n] = 1.0; for (int r = 0; r < M; r++) //枚举轮 { for (int i = n; i >= 0; i--) { int jub = min(i, n - i); double t = 0.0; for (int j = 0; j <= jub; j++) { t = max(t, P * prv[i + j] + (1 - P) * prv[i - j]); } nxt[i] = t; } swap(prv, nxt); } int i = (ll) X * n / (1e6); // cout << fixed << setprecision(6) << prv[i] << endl; printf("%.6f ", prv[i]); } int main() { freopen("E:\c2.txt", "r", stdin); freopen("E:\out2.txt", "w", stdout); int k; // cin >> k; scanf("%d",&k); for (int kase = 1; kase <= k; kase++) { // cin >> M >> P >> X; scanf("%d%lf%d", &M, &P, &X); printf("Case #%d: ", kase); // cout << "Case #" << kase << ": "; solve(); } fclose(stdin); fclose(stdout); return 0; }