Test instructions
You have x dollars for the M-wheel gambling game. Each round can be held by any part of the money as a bet (bet 0 yuan for this round), the bet can be fractional, not necessarily an integer. Each round wins the probability is P, wins the wager to double, loses the wager to be gone. If you finally hold at least 1000000 yuan, you can take all the money. It is required to calculate the probability of obtaining at least 1000000 yuan in the optimal strategy.
Data range:
0<=p<=1
1<=x<=1000000
1<=m<=15
1 intM, X; 2 DoubleP; 3 Doubledp[2][(1<< the) +1]; 4 voidSolve ()5 { 6 intn =1<<M; 7 Double*pre = dp[0], *NXT = dp[1]; 8memset (PRE,0,sizeof(Double) * (n +1)); 9 ///memset (pre, 0, sizeof); This initialization is not possible because the pre is a double-type pointer, not an entire array. TenPre[n] =1.0; One for(intR =0; R < M; r++)///enumerate the first few rounds A { - for(inti =0; I <= N; i++)///enumerates which states are currently - { the intStep = min (i, n-i);///If step is greater than N/2, the transfer may be more than n - Doublet =0.0; - for(intj =0; J <= Step; J + +)///enumerates all possible methods of the current - { +t = max (t, P * pre[i + j] + (1-P) * pre[i-j]);///find the desired maximum value - } +Nxt[i] =T; A } atSwap (pre, NXT);///swaps the values of two arrays to scroll - } - inti = (LL) X * N/1000000;///find the x corresponding to the first few pieces - //for (int i = 0; I <= N; i++) cout << ' * ' << pre[i] << Endl; -printf"%.6lf\n", Pre[i]); -}
Code Jam APAC local onsites problem C. millionaire--probability DP