Code Jam APAC Local onsites problem C. millionaire--probability DP

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.